0

I am currently developing a simple kernel for a university course, in which I am asked to implement a function that outputs all the register values. So far, I have managed to write the following:

    push rbp
    mov rbp, rsp
    pushState

    push rsi
    push rdi
    push rdx


    mov rcx, 5
    mov rdx, raxMsg
    mov rsi, 1
    mov rdi, 1
    call sysCallDispatcher

    mov rcx, 16
    mov rdx, [rax]
    mov rsi, 1
    mov rdi, 1
    call sysCallDispatcher

    pop rdx
    pop rdi
    pop rsi

    popState
    leave
    ret

This is just an example for the RAX register (raxMsg is defined as "RAX: " and sysCallDispatcher manages the syscall to output a write syscall). My question is: when I load what is in RAX, what type of variable is being stored in rdx? Is it an int I have to convert to string? Thank you.

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
zetzot37
  • 35
  • 3
  • 3
    `mov rdx, [rax]` loads the 8 bytes starting from the address stored in `rax`, interpreted as a little-endian quadword – ecm May 28 '21 at 15:34
  • 3
    "Type" is a high-level language concept. Registers just have bits. What they represent is a matter of how they are used. The function sysCallDispatcher() probably expects something to be in DX--look at its documentation. – Lee Daniel Crocker May 28 '21 at 18:23
  • 1
    If your system call returns a pointer in RAX, that makes sense. Otherwise, if you want to print the original RAX value, you'll need to push / pop it around the first system call. And yes, unless you have a "system call" that formats numbers into strings for you, you'll have to do that yourself. [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) shows the algorithm, and x86-64 code to do so, including a Linux `write` system call. – Peter Cordes May 28 '21 at 19:59

0 Answers0