0

Working on an assembly project, I'm trying to use "puts" to print an integer saved in a temporary variable. I'm aware that the integer has to be reformatted to a string format before it can be printed and my question is how to do that. Using AT&T syntax. for example:

.data
temp: .quad 0
outbuf: .space 64
.global main
main:
movq $5, temp

reformat: 
// the function to reformat the temp variable and move it to outbuf

printBuf:
movq outbuf, %rdi
call puts
ret
  • My answer on the linked duplicate can be easily adapted to produce a 0-terminated string instead of `\n` terminated. – Peter Cordes Sep 28 '20 at 01:30
  • Also, `movq outbuf, %rdi` loads the first 8 bytes. You want `mov $outbuf, %edi` or `lea outbuf(%rip), %rdi` to put the address in a register, if you use a static buffer at all instead of reserving space on the stack like my linked answer does. – Peter Cordes Sep 28 '20 at 01:33
  • 1
    If you're using the C library anyway, why not just call `printf` instead of `puts` and avoid reinventing this wheel? – Nate Eldredge Sep 28 '20 at 02:29

0 Answers0