.text
.align 2
.global main
.equ val,0x4712 # 16-bit binary code for 0x4712: 0100 0111 0001 0010
# Program code starts now
main:
movi r16,val
movi r17,0
loop: addi r17,r17,1
subi r16,r16,1
bne r16,r0,loop
stop: br stop
How should I do to translate the above to machine code? I need to know how to make the translation besides the actual code. I figure I could try and get the opcodes for the instructions but the movi is a pseudoinstruction and I don't know where I can get it. Should I read it in the Nios II manual?
Update
The first four instructions are type immediate so that field form should be used. movi and subi both are pseudoinstruktions implemented in addi so the opcode for addi will be used. I was helped and I know that the instruction movi r16, val will translate to
00000100000100011100010010000100
so the opcode is 000100 binary which is 0x04 in hex base which the manual also states is the opcode for addi. So I think we have the first four opcodes, they are all 000100.
Update 2
I think I know the opcode and the immediate field of most of the instructions now:
The sequence 0100011100010010 is 0x4712 which is the variable val that was declared with .equ,
So the first four opcodes should be 000100 since they're all addi and addi says it's 0x04. How to translate the two five-bit fields for the registers I don't know right now but could be checking with the manual. It says 'brhas opcode 0x06 so it should say 000110 in the opcode for br.bne` has opkod 0x1E which binary is 011110 = 30 (?)
Is this a correct beginning?