Registers are used to store result of computations:
Note: you must save (= store) the result in its variable in memory to complete the assignment statement !
The "store register" instructions are used to store a value in a register into memory:
Note: there are many syntax forms of the "store register" instruction
We will learn to store a value in a register into these 3 integer (whole number) typed variables
|
We start with the byte typed variable
Note:
The value in a
register is
a 32 bits
2s complement representation
We will store this
32 bits
representation into
a byte (= 8 bits)
variable
Therefore:
overflow is
possible !!!
Syntax and meaning of the strb instruction:
strb rN, [rM] // store register byte
Store 1 byte from register rN to memory
at the address given by the value in rM
The byte stored at the right of register rN:
|
Note:
initialize
rM = address of a short variable
before you use the
strb instruction
Note:
the
strb instruction
will
convert the
32 bits
int value
in register
rN
into a
byte
strb r1, [r0]: (1) sends out r0 on the address bus and the byte in r1 on the data bus
The CPU will issue a write command on the control bus
strb r1, [r0]: (2) the memory will store the data in the designated memory location:
The old data will be overwritten
Recall that for value in rage [−128, 127], the int → byte conversion will produce correct results:
Value byte int (32 bits 2s compl code) ------- ------- ---------------------------------- 127 01111111 00000000000000000000000001111111 ... 3 00000011 00000000000000000000000000000011 2 00000010 00000000000000000000000000000010 1 00000001 00000000000000000000000000000001 0 00000000 00000000000000000000000000000000 -1 11111111 11111111111111111111111111111111 -2 11111110 11111111111111111111111111111110 -3 11111101 11111111111111111111111111111101 ... -128 10000000 11111111111111111111111110000000 |
If the register contains a values outside the range [−128, 127], then strb will result in overflow
Reminder:
|
We will also use the address in the register in the store operation !!!
// r1 = 00000000 00000001 00000001 00000111 // Store byte in register r1 into (memory) variable b movw r0, #:lower16:b // Moves the address of memory movt r0, #:upper16:b // variable b into register r0 strb r1,[r0] // Store byte value from r1 // into memory location r0 .data b: .byte -2 // variable b (byte b = -2 or 11111110) |
Result of the execution of strb r1,[r0]:
DEMO:
/home/cs255001/demo/asm/2-mov/str-v2.s
Use tmp/ldr+str.s
Syntax and meaning of the strh instruction:
strh rN, [rM] // store register half
Store 2 bytes from register rN to memory
at the address given by the value in rM
The 2 bytes stored at the right of register rN:
|
Note:
initialize
rM = address of a short variable
before you use the
strb instruction
Note:
the
strb instruction
will
convert the
32 bits
int value
in register
rN
into a
short
strh r1, [r0]: (1) sends out r0 on the address bus and the short in r1 on the data bus
The CPU will issue a write command on the control bus
strh r1, [r0]: (2) the memory will store the data in the designated memory location:
The old data will be overwritten
Recall that for value in rage [−32768, 32767], the int → short conversion will produce correct results:
Value short int (32 bits 2s compl code) ----- ---------------- -------------------------------- 32767 0111111111111111 00000000000000000111111111111111 ... 3 0000000000000011 00000000000000000000000000000011 2 0000000000000010 00000000000000000000000000000010 1 0000000000000001 00000000000000000000000000000001 0 0000000000000000 00000000000000000000000000000000 -1 1111111111111111 11111111111111111111111111111111 -2 1111111111111110 11111111111111111111111111111110 -3 1111111111111101 11111111111111111111111111111101 ... -32768 1000000000000000 11111111111111111000000000000000 |
If the register contains a values outside the range [−32768, 32767], then strh will result in overflow
// r1 = 00000000 00000001 00000001 00000111 // Store short in register r1 into (memory) variable s movw r0, #:lower16:s // Moves the address of memory movt r0, #:upper16:s // variable s into register r0 strh r1,[r0] // Store short value from r1 // into memory location r0 .data s: .2bytes -3 // variable s (short = -3 or 1111111111111101) |
Result of the execution of strh r1,[r0]:
DEMO: /home/cs255001/demo/asm/2-mov/str-v2.s
Syntax and meaning of the str instruction:
str rN, [rM]
Store 4 bytes from register rN to memory
at the address given by the value in rM
The 4 bytes comprise of the register rN:
|
Note:
initialize
rM = address of a short variable
before you use the
str instruction
str r1, [r0]: (1) sends out r0 on the address bus and the all 32 bits in r1 on the data bus
The CPU will issue a write command on the control bus
str r1, [r0]: (2) the memory will store the data in the designated memory location:
The old data will be overwritten
// r1 = 00000000 00000001 00000001 00000111 // Store int in register r1 into (memory) variable i movw r0, #:lower16:i // Moves the address of memory movt r0, #:upper16:i // variable i into register r0 str r1,[r0] // Store int value from r1 // into memory location r0 .data i: .4byte -4 // variable i (int i = -4) |
Result of the execution of str r1,[r0]:
DEMO: /home/cs255001/demo/asm/2-mov/str-v2.s