Write LEGv8 assembly language programs for the following C p
Solution
prob 1
Let the reference of p be X22
LDUR X9,[X22,#80] //index 8 required offset of 80, temporary register X9 gets p[10]
LDUR X10,[X22,#240] //index 30 required offset of 240, temporary reg X10 gets p[30]
ADD X9,X10,X9 //X10+X9 stored in X9, X9 gets p[10]+p[30]
ADD X9,#25 //X9 gets p[10]+p[30]+25
STUR X9,[X22.#160] //stores p[10]+p[30]+25 in p[20] as index 20 requires offset of 160
prob 2
for ADD opcode is 10001011000, opcode size is 11 and instruction is R format
for LDUR opcode is 11111000010, opcode size is 11 and instruction is D format
for STUR opcode is 11111000000, opcode size is 11 and instruction is D format
for D format instruction
where, Rn = base register
op2 = expand opcode field
Rt = destination number
For R format instuction
where, shamt = how many position to shaft
Shift left logical (LSL)
Shift right logical (LSR) \"
Now is the 1st instuction x22[#80] is loaded in X9 , op2 = 0, Rt: X9, Rn: X22
so machine code will be 11111000010 010110000 00 10110 01001 or in decimal 1986 80 0 22 9
in 2nd instuction [X22,#240] is loaded in X10 so machine code will 11111000010 011110000 00 10110 1010
similary for ADD X9,X10,X9 machine code will 10001011000 01001 000000 01010 01001
for ADD X9,#25 machine code: 10001011000 01001 011001 00000 00000
for STUR X9,[X22.#160], op2=0,machine code will be 11111000000 010100000 00 10110 01001
| opcode 11 bits | offset 9 bits | op2 2bits | Rn 5 bits | Rt 5bits |
![Write LEGv8 assembly language programs for the following C program fragments. Please make sure to add any necessary comments. P [20] = P [10] + P [30] + 25; Sh Write LEGv8 assembly language programs for the following C program fragments. Please make sure to add any necessary comments. P [20] = P [10] + P [30] + 25; Sh](/WebImages/36/write-legv8-assembly-language-programs-for-the-following-c-p-1107124-1761586214-0.webp)