Hand Assemble the Following Instructions
MOV R1, R2
010011000 0 001 010
0x4C0A
MOVL #1234, R1
01100 00110100 001
0110 0001 1010 0001
0x61A1
MOVH #1234, R1
01111 00010010 001
0111 1000 1001 0001
0x7891
LD R2, R4
0101 1000 0001 0100
0x5814
ST R4 R1+
010111 1 01 0 100 001
0101 1110 1010 0001
0x5EA1
LDR R0, #4, R1
10 0000100 0 000 001
1000 0010 0000 0001
0x8201
ADD R1 R2
01000000 0 0 001 010
0100 0000 0000 1010
0x400A
ADD.B R1 R2
01000000 0 1 001 010
0100 0000 0100 1010
0x404A
2023/05/11
Show how to initialize a register
MOVL #1234 R1
MOVH #1234 R1
ORG #100 ← sets location counter to 0x0100
WORD directive allows us to store a 16 bit value. ← there is no instruction for WORD, but the assembler recognizes it as a directive
DATA WORD #1234 (# == hex value) ~~~ DATA is a label. It is the value of the address, in this case, 100
(data is stored in locations 0100 and 0101, since it is a 16 bit value. location 0100 holds 34, location 0101 holds 12 since it is little endian)
ORG directive specifies origin. Changes the Location counter.
ORG #1000
how could a program at ORG #1000 access the value at the location?
we can give it a label.
MOVL DATA R0
MOVH DATA R0
moving the address of data into R0
contents of R0 are now 0x0100
now we can load the value at the address in r0 into r1
LD R0 R1
this puts the value of Mem[R0] into R1
Mem[0100] == #1234
The benefit of loading from memory is you can increment the value later if you want to. Even though loading an immediate uses fewer instructions, you can't change the immediate value. Index