Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operand Addressing –No instruction for reg-to-reg transfer –Cannot do memory-memory transfers with single instruction –sw instruction violates (dest, source)

Similar presentations


Presentation on theme: "Operand Addressing –No instruction for reg-to-reg transfer –Cannot do memory-memory transfers with single instruction –sw instruction violates (dest, source)"— Presentation transcript:

1 Operand Addressing –No instruction for reg-to-reg transfer –Cannot do memory-memory transfers with single instruction –sw instruction violates (dest, source) spec of operands Imm Reg Mem Reg Mem Reg SourceDestination li $t1, 0x4 la $t1, A sw $t1,A($t2) lw $t1,A($t2) C Analog temp = 0x4; temp2 = &A; A[n] = temp; temp = A[n]; Addr

2 Addressing Modes Indirect(R) Mem[Reg[R]] – Register R specifies memory address lw $t1, ($t2) IndexedD(R) Mem[Reg[R]+D] – Register R specifies start of memory block – Constant displacement D specifies offset lw $t1, 8($t2)

3 .data array:.word0x37, 0x55, 0xF.text la $s0, array la$s1, array+4 la$s2, 8($s0) li$a0, 4 lw$t0, 0($s0) lw$t3, array($a0) lw$t1, 8($s0) lb$t2, ($s0) Example

4 void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } # xp in $a0, yp in $a1 swap: lw $t0,($a0) # t0=*xp lw $t1,($a1) # t1=*yp sw $t1,($a0) # *xp=t1 sw $t0,($a1) # *yp=t0 jr $ra

5 Understanding Swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } RegisterVariable Value $a0xp 120 $a1yp 124 $t0 $t1 # xp in $a0, yp in $a1 swap: lw$t0, ($a0) lw$t1, ($a1) sw$t1, ($a0) sw$t0, ($a1) jr$ra 123 456 0x124 0x120

6 RegisterVariable Value $a0xp 120 $a1yp 124 $t0 456 $t1 # xp in $a0, yp in $a1 swap: lw$t0, ($a0) lw$t1, ($a1) sw$t1, ($a0) sw$t0, ($a1) jr$ra 123 456 0x124 0x120

7 RegisterVariable Value $a0xp 120 $a1yp 124 $t0 456 $t1 123 # xp in $a0, yp in $a1 swap: lw$t0, ($a0) lw$t1, ($a1) sw$t1, ($a0) sw$t0, ($a1) jr$ra 123 456 0x124 0x120

8 RegisterVariable Value $a0xp 120 $a1yp 124 $t0 456 $t1 123 # xp in $a0, yp in $a1 swap: lw$t0, ($a0) lw$t1, ($a1) sw$t1, ($a0) sw$t0, ($a1) jr$ra 123 0x124 0x120

9 RegisterVariable Value $a0xp 120 $a1yp 124 $t0 456 $t1 123 # xp in $a0, yp in $a1 swap: lw$t0, ($a0) lw$t1, ($a1) sw$t1, ($a0) sw$t0, ($a1) jr$ra 456 123 0x124 0x120

10 Arithmetic Operations add $t1, $t2, $t2 (addi $t1, $t2, 0x32) sub $t1, $t2, $t2 mul $t1, $t2, $t2 div $t1, $t2, $t2 and (andi), or (ori), xor (xori) sll $t1, $t2, 2 (shift left logical) sllv (sll variable) sra (shift right arithematic) srl

11 Directives (Establish initial data structure).ascii (store string in memory with no null-termination).asciiz (store string in memory with null termination).byte b1,..,bn.word w1,..,wn.word w:n (store w into n successive words).space n.datadata segment.textassembly instructions Directives


Download ppt "Operand Addressing –No instruction for reg-to-reg transfer –Cannot do memory-memory transfers with single instruction –sw instruction violates (dest, source)"

Similar presentations


Ads by Google