Warning:
|
Warning:
|
The next examples will show you what can go wrong if you don't...
Consider a program with 2 short typed variables:
.data x: .2byte 254 // short typed variable y: .2byte 1 // short typed variable |
How these 2 short variables are stored in memory:
movw r0, #:lower16:x // Moves the address of memory movt r0, #:upper16:x // variable x into register r0 ldrsb r1,[r0] ?? ldr r1,[r0] ?? |
Use: tmp/orig.s DEMO: /home/cs255001/demo/asm/2-mov/wrong-ldr.s
Effect when you use the correct ldrsh r1, [r0] instruction to fetch short x:
The value in
short x =
254
The ldrsh
instruction
loads
254 into
the register r1
Effect when you use the incorrect ldrsb r1, [r0] instruction to fetch short x:
The value in
short x =
254
The ldrsb
instruction
loads
-2 (error !) into
the register r1
(because it did not
fetch the
first byte)!
Effect when you use the incorrect ldr r1, [r0] instruction to fetch short x:
The value in
short x =
254
The ldr
instruction
loads
65790(error!) into
the register r1
(because it
fetched some
extraneous data)!
Consider a program with 2 short typed variables:
.data x: .2byte 4 // short typed variable y: .2byte 7 // short typed variable |
How these 2 short variables are stored in memory:
movw r0, #:lower16:x // Moves the address of memory movt r0, #:upper16:x // variable x into register r0 mov r1, #-2 strb r1,[r0] ?? str r1,[r0] ?? (Watch y !!) |
Use: tmp/orig.s DEMO: /home/cs255001/demo/asm/2-mov/wrong-str.s
Effect when you use the correct strh r1, [r0] instruction to write the short x variable:
The value in
register R1 =
-2
The strh
instruction
changes
the value in
x to
-2
Effect when you use the incorrect strb r1, [r0] instruction to write the short x variable:
The value in
register R1 =
-2
The strb
instruction
changes
the value in
x to
254
(because it
did not
update
2nd byte!)
Effect when you use the incorrect str r1, [r0] instruction:
The str
instruction will
write
4 bytes to
memory !!
The
variable y is
also
updated !!