I'm learning MIPS64 and using EduMIPS64 simulator.
I understand the instructions of the following example, I tried to execute it cycle after cycle but I don't get how the compiler knows which number or string matches to corresponding placeholder and how all related to format_str
so in the end of the .code
section, it's enough to put the address of format_str
in r14
I know that System calls expect that the address of their parameters is stored in register R14, but how all the others relate to this address(format_str
)?
For each
%s
,%d
or%i
placeholder,SYSCALL 5
expects a parameter, starting from the address of the previous one. When the SYSCALL finds a placeholder for an integer parameter, it expects that the corresponding parameter is an integer value, when if it finds a placeholder for a string parameter, it expects as a parameter the address of the string.
I tried understand it by the memory representation with no success.
.data
format_str: .asciiz "%dth of %s:\n%s version %i.%i is being tested!"
s1: .asciiz "June"
s2: .asciiz "EduMIPS64"
fs_addr: .space 4
.word 5
s1_addr: .space 4
s2_addr: .space 4
.word 0
.word 5
test:
.code
daddi r5, r0, format_str
sw r5, fs_addr(r0)
daddi r2, r0, s1
daddi r3, r0, s2
sd r2, s1_addr(r0)
sd r3, s2_addr(r0)
daddi r14, r0, fs_addr
syscall 5
syscall 0
Thanks.