This has been asked before but I can't seem to figure it out: how do I print an ascii value in assembly x86 32 bit.
mov eax, 10
add eax, 48
;print contents of eax
This has been asked before but I can't seem to figure it out: how do I print an ascii value in assembly x86 32 bit.
mov eax, 10
add eax, 48
;print contents of eax
Here's how to do it using printf on 32-bit Linux:
~/tmp: cat t.s
.intel_syntax noprefix
.global main
main:
mov eax, 10
add eax, 48
push eax
push offset .L1
call printf
add esp, 8
xor eax, eax
ret
.L1: .asciz "%d\n"
~/tmp: gcc -m32 t.s
~/tmp: a.out
58
~/tmp:
Here's how to do it on 64-bit Linux:
~/tmp: cat t.s
.intel_syntax noprefix
.global main
main:
sub rsp, 8
mov eax, 10
add eax, 48
lea rdi, .L1[rip]
mov esi, eax
xor eax, eax
call printf
add rsp, 8
xor eax, eax
ret
.L1: .asciz "%d\n"
~/tmp: gcc t.s
~/tmp: a.out
58
~/tmp:
It depends on how you want to print. You can...
Link against a print routine in a library. Use bios interrupt 0x10 to print to the screen. Print using a serial port (if you are doing low level coding).