|
|
Note:
|
construct 1: Construct 2: ============================== =========================== sethi %hi(123456789), %l5 sethi %hi(123456789), %l5 add %l5, %lo(123456789), %l5 ld [%l5 + %lo(123456789], %l5 |
%hi(123456789) = 123456789 / 1024 = 120563 %lo(123456789) = 123456789 % 1024 = 277 Note: 120563 * 1024 = 123456512 |
sethi %hi(123456789), %l5 ; %l5 = [ ............ | ..... ] ; ^^^^^^^^^^^^^^ ^^^^^^^ ; 120563 0 ; ; Decimal value of %l5 = 120563 * 1024 ; = 123456512 add %l5, %lo(123456789), %l5 ; %l5 = 123456512 + 277 = 123456789 |
Effect: register %l5 = 123456789
sethi %hi(123456789), %l5 ; %l5 = [ ............ | ..... ] ; ^^^^^^^^^^^^^^ ^^^^^^^ ; 120563 0 ; ; Decimal value of %l5 = 120563 * 1024 ; = 123456512 ld [%l5 + %lo(123456789)], %l5 ; %l5 + %lo(123456789) = 123456512 + 277 ; = 123456789 ; ; The ld instruction will USE the address 123456789 ; ; So the value in memory location 123456789 ; is moved into register i5 !!! |
Effect: register %l5 = value stored in memory address 123456789
Move the constant 987654 into a register (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #987654, d5 sethi %hi(987654), %l0 add %l0, %lo(987654), %i5 |
Note:
|
Assembler code:
int x; Move the address of variable from x into a register (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #x, d5 sethi %hi(x), %l0 add %l0 ,%lo(x), %i5 x: ds.l 1 .align 4 x: .skip 4 |
Solution 1: (slow but clear solution)
int x; Move the value stored in variable x into a register (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l x, d5 sethi %hi(x), %l0 add %l0, %lo(x), %l0 ; %l0 = address of x ! ld [%l0 + 0], %i5 |
Solution 2: (faster but less clear solution)
int x; Move the value stored in variable x into a register (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l x, d5 sethi %hi(x), %l0 ld [%l0 + %lo(x)], %i5 ; %l0 + %lo(x) = address of x ! |
Solution 1: (slow but clear solution)
int x; Move the value in %i5 to variable x (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l d5, x sethi %hi(x), %l0 add %l0, %lo(x), %l0 ; %l0 = address of x ! st %i5, [%l0 + 0] |
Solution 2: (faster but less clear solution)
int x; Move the value in %i5 to variable x (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l d5, x sethi %hi(x), %l0 st %i5, [%l0 + %lo(x)] ; %l0 + %lo(x) = address of x ! |
int A[100]; Move the value from variable A[7] into a register Offset to A[7] = 7 * 4 = 28 (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #A, a0 sethi %hi(A), %l0 move.l 28(a0), d5 add %l0, %lo(A), %l0 ; %l0 = address of array A ld [%l0 + 28], %i5 ; %l0 + 28 = address of A[7] |
int A[100]; Move the value from register to variable A[9] Offset to A[9] = 9 * 4 = 36 (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #A, a0 sethi %hi(A), %l0 move.l d5, 36(a0) add %l0, %lo(A), %l0 ; %l0 = address of array A st %i5, [%l0 + 36] ; %l0 + 36 = address of A[9] |
int A[100]; int i; Move the value from variable A[i] into a register (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #A, a0 sethi %hi(A), %l0 add %l0 + %lo(A), %l0 // l0 = address of array A move.l i, d1 sethi %hi(i), %l1 ld [%l1 + %lo(i)], %l1 // l1 = value of variable i muls #4, d1 smul %l1, 4, %l1 // l1 = 4*i move.l 0(a0, d1.w), d5 ld [%l0 + %l1], %i5 |
int A[100]; int i; Move value in a register to the memory variable A[i] (d5 in M68000 and i5 in SPARC) M68000 SPARC =============== ================= move.l #A, a0 sethi %hi(A), %l0 add %l0 + %lo(A), %l0 // l0 = address of array A move.l i, d1 sethi %hi(i), %l1 ld [%l1 + %lo(i)], %l1 // l1 = value of variable i muls #4, d1 smul %l1, 4, %l1 // l1 = 4*i move.l d5, 0(a0, d1.w) st %i5, [%l0 + %l1] |
class List { int value; List next; } List head; |