在程序集x86中打印一个ascii值

时间:2019-12-17 17:23:27

标签: assembly ascii

以前曾有人问过这个问题,但我似乎无法弄清楚:如何在32位汇编x86中打印ascii值。

mov eax, 10
add eax, 48
;print contents of eax

2 个答案:

答案 0 :(得分:0)

这取决于您要如何打印。 你可以...

链接到库中的打印例程。 使用BIOS中断0x10打印到屏幕上。 使用串行端口进行打印(如果正在执行低级编码)。

答案 1 :(得分:0)

这是在32位Linux上使用printf的方法:

~/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:

这是在64位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: