Вы находитесь на странице: 1из 5

- Chapter 2 -

lw

$t2, 4($s1)

lw

$t3, 8($s1)

addi

$t3, $t3, -5

add

$t1, $t2, $t3

sw

# 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

12

ab

ef

cd

cd
12 ab

ef

sll

$t0, $s3, 2

12 12

# 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

$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])

f = &A[0]+ &A[0] // or f= 2*(&A[0])

0x8000 0000
+ 0xD000 0000
= 0x5000 0000

overflow

s0, s1, s2, s3, s4, s6, s7

$t2, $t1, $t0

A[1]=&A[0]

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

Overflowed,

44 MOD 32 = 12

sll $t2, $t0, 44

# $t2 = $t0 << 44 = $t0 << 12

or $t2, $t2, $t1

# $t2 = $t2 | $t1 = 0xAAAAA000 | 0x12345678 = 0xBABEF678

, Second
sll $t2, $t0, 44

= 0xAAAAA000

Dont care about limitation of constants.


# 44 32bit 0 .

all the digits in $t2 are filled with zeros because it is shifted more than 32 bit
or $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

srl $t2, $t0, 3

# $t2= $t0 << 4 = 0xAAAAAAA0


# $t2= $t2 & 0xFFFFFFFF = 0xAAAAAAA0 & 0xFFFFFFFF = 0xAAAAAAA0

# $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 00012 = 819310


lower 16bit : 0100 1001 0010 01002 = 1872410
lui

$t1, 8193

# or ))

lui

$t1, 0x2001

ori

$t1, $t1, 18724

# or ))

ori

$t1, $t1, 0x4924

Вам также может понравиться