Another benefit of pseudo instructions is that it reduces the number of mistakes. It'll always get the correct instructions, like the imm20 vs. imm12 are calculated and used correctly with the correct real instructions.
I really appreciate these videos! I have one question with regard to pseudo instructions. In the case of a long jump, you showed j imm32 becomes lui t0, imm20 jalr zero, imm12(t0) Does this mean that whenever a 'j' or 'call' pseudo-instruction is used you have to assume t0 is clobbered? Are there any other pseudo-instructions that could clobber registers?
.align will align data of the next directive to the requested boundary. Only power of 2 values are allowed, e.g.: a: .byte 0x00 .align 4 b: .word 0x12345678 will align the 4 byte (word) value accessible by the label b to the next address which is divisible by 4. The gap between label a and b, if any, will be filled either with zeros or in some architecture implementation with the value for the "nop" instruction.
At 7:10 the problem is that you need the length of the program not to change depending on things you haven't seen yet. The simple assemblers I have written are two pass and the first pass works out the label values. So any pseudo instruction needs to have a known length when you process it.
Another benefit of pseudo instructions is that it reduces the number of mistakes. It'll always get the correct instructions, like the imm20 vs. imm12 are calculated and used correctly with the correct real instructions.
Great
I really appreciate these videos!
I have one question with regard to pseudo instructions. In the case of a long jump, you showed
j imm32
becomes
lui t0, imm20
jalr zero, imm12(t0)
Does this mean that whenever a 'j' or 'call' pseudo-instruction is used you have to assume t0 is clobbered? Are there any other pseudo-instructions that could clobber registers?
.align will align data of the next directive to the requested boundary. Only power of 2 values are allowed, e.g.:
a: .byte 0x00
.align 4
b: .word 0x12345678
will align the 4 byte (word) value accessible by the label b to the next address which is divisible by 4. The gap between label a and b, if any, will be filled either with zeros or in some architecture implementation with the value for the "nop" instruction.
Yes, that’s what you’d think. But for my system, something is not working… computers!?!?!
At 7:10 the problem is that you need the length of the program not to change depending on things you haven't seen yet. The simple assemblers I have written are two pass and the first pass works out the label values. So any pseudo instruction needs to have a known length when you process it.
There is a VS Code extension that runs RISC-V assembly code, I'll run the explained instruction in order to understand them better.