Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Writeln in assembler

NASM code for writing the integer in eax to stdout.

   1  
   2  segment .bss
   3          writeTemp       resb    10
   4  
   5  segment .text
   6  _writeln:                               
   7          MOV     ebx,    eax             ; Number is already in eax
   8          MOV     ecx,    10
   9          XOR     edi,    edi
  10  L0:
  11          CMP     eax,    0
  12          JE      L1
  13          ADD     edi,    1
  14          XOR     edx,    edx
  15          IDIV    ecx
  16          JMP     L0
  17  L1:
  18          ADD     edi,    writeTemp       ; Length of the number is in edi
  19          MOV     esi,    edi
  20          MOV byte        [edi],  10      ; Add a newline
  21          SUB     edi,    1
  22          XOR     eax,    eax
  23  L2:                             
  24          CMP     ebx,    0
  25          JE      L3
  26          MOV     eax,    ebx
  27          XOR     edx,    edx
  28          IDIV    ecx
  29          ADD     dl,     48
  30          MOV     [edi],  dl
  31          SUB     edi,    1
  32          MOV     ebx,    eax
  33          JMP     L2                      ; Number has been written to writeTemp from tail to head
  34  L3:                             
  35          MOV     eax,    4
  36          MOV     ebx,    1
  37          MOV     ecx,    writeTemp
  38          MOV     edx,    esi
  39          SUB     edx,    writeTemp
  40          ADD     edx,    1
  41          INT     80h
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS