问题描述:

I can use 5 empty registers. They are set to zero. I want to set a register to the number above efficiently.

AND R1, R1, #0 ;

ADD R1, R1, x8000

"x8000" is hexadecimal for the number i'm trying to put into the register. I think the code above did not work because only 5 digit binary numbers can be passed ass immediate values for add instructions. They are later zero-extended to 16 bits. Therefore trying to pass a 16 bit number does not work. This is small part of a program I am working on.

网友答案:

You're right, when you use ADDi (immediate) you can only use numbers between -16 and 15 when adding to a register.

You can either use the ADDi command over and over until you have the number you want in the register (not recommended) or you can load a constant from memory.

.orig x3000

MAIN
AND R1, R1, #0      ; Clear R1
LD R2, VAR_1        ; Load x8000 into R2
ADD R1, R1, R2      ; R1 = R1 + R2

HALT
; Variables
VAR_1   .FILL x8000

.END
相关阅读:
Top