Outputting integers in assembly on Linux

前端 未结 2 715
别跟我提以往
别跟我提以往 2020-12-10 16:13

This needs to be done in pure assembly (ie. no libraries or calls to C).

I understand the essence of the problem: one needs to divide the integer by 10, convert the

2条回答
  •  余生分开走
    2020-12-10 17:07

    You properly set ecx to 10 at the top of your routine, but overwrite ecx later:

    mov eax, 4              ; sys_write
    mov ebx, 1              ; to STDOUT
    mov ecx, edx ;;; oops -- lost the 10
    mov edx, 1
    int 0x80
    

    Try moving the loop up one line, so ecx is re-initialized to 10 each time through the loop.

提交回复
热议问题