- Chapter 2 -
lw
$t2, 4($s1)
lw
$t3, 8($s1)
addi add sw
$t3, $t3, -5 $t1, $t2, $t3
# h=h-5
$t1, 0($s1)
or
f : $s0, g : $s1, h : $s2 addi $t0, $s2, -5 add $s0, $t0, $s1
little endian
big endian
0
12
0
ab
4
ef
4
cd
8
cd
8
ef
12
ab
12
12
sll
$t0, $s3, 2
# offset
# sll : shift left logical
sll
$t1, $s4, 2
# offset
add
$t0, $t0, $s6
# A[i]
add
$t1, $t1, $s6
# A[j]
lw
$t0, 0($t0)
# A[i] -> t0
lw
$t1, 0($t1)
# A[j] -> t1
add sw
f
g h
i
j
s0, s1, s2, s3, s4, s6, s7
$t2, $t1, $t0 $t2, 32($s7)
addi
$t0, $s6, 4
# $t0 = addr of A[1]
add
$t1, $s6, $0
# $t1 = addr of A[0]
sw
$t1, 0($t0)
# A[1] = addr of A[0]
lw
$t0, 0($t0)
# $t0 = A[1] = addr of A[0]
add
$s0, $t1, $t0
# $s0 = (addr of A[0]) + (addr of A[0])
A[1]=&A[0] f = &A[0]+ &A[0] // or f= 2*(&A[0])
0x8000 0000 + 0xD000 0000 = 0x5000 0000
overflow
A B
0x8000 0000 - 0xD000 0000 = 0xB000 0000
Right result
0x8000 0000
0x5000 0000
+ 0xD000 0000
+ 0x8000 0000
= 0x5000 0000
= 0xD000 0000
Overflow
sll 명령어의 경우 32비트 숫자에서 상수의 범위가 0~31이므로, 원래는 Error가 발생한다. (qtsim에서 에러 발생) 그러나 답을 원하는 경우, 문제에서 두 가지로 해석할 수 있다. Originally SLL instruction takes constant value from 0 to 31. So it makes error.(qtsim shows error)
But if you we want to make answer from this question. we can get answer as below. 첫 번째는, First sll $t2, $t0, 44 or $t2, $t2, $t1 두 sll all or
Overflowed, 44 MOD 32 = 12 # $t2 = $t0 << 44 = $t0 << 12 = 0xAAAAA000 # $t2 = $t2 | $t1 = 0xAAAAA000 | 0x12345678 = 0xBABEF678
번째는, Second Don’t care about limitation of constants. $t2, $t0, 44 # 44번 시프트 하는데 32bit를 넘으므로 0이 된다. the digits in $t2 are filled with zeros because it is shifted more than 32 bit $t2, $t2, $t1 # $t2 = $t2 | $t1 = 0x00000000 | 0x12345678 = 0x12345678
Both Answers are graded as correct for this time But if this question(or similar) is being set on exam, first answer will be the only one accepted
sll $t2, $t0, 4 andi $t2, $t2, -1
# $t2= $t0 << 4 = 0xAAAAAAA0 # $t2= $t2 & 0xFFFFFFFF = 0xAAAAAAA0 & 0xFFFFFFFF = 0xAAAAAAA0
srl $t2, $t0, 3 # $t2= $t0 >> 3 = 0x15555555 andi $t2, $t2, 0xFFEF # $t2= $t2 & 0x0000FFEF = 0x15555555 & 0x0000FFEF = 0x00005545
nor $t1, $t2, $0
$0 < $t0, then $t2 = 1 $t2 > $0, then go to ELSE $t2 = 1 + 2 = 3 $t2 = 3
upper 16bit : 0010 0000 0000 0001 2 = 819310 lower 16bit : 0100 1001 0010 0100 2 = 1872410 lui
$t1, 8193
# or )) lui
$t1, 0x2001
ori
$t1, $t1, 18724
# or )) ori
$t1, $t1, 0x4924