[list -] %INCLUDE "Along32.inc" %INCLUDE "Macros_Along.inc" [list +] ;--------------------------------------------------------------------- extern PrintBinary ; HLL prototype: void PrintBinary(int n); ; Prints the internal binary representation of n ; Receives: EAX = signed 32-bit integer ; Returns: nothing ;--------------------------------------------------------------------- SECTION .data hrule times 51 db ('-') db 10,0 spacer1 times 2 db ' ' db 0 spacer2 times 4 db ' ' db 0 header times 2 db ' ' db ' Decimal ' times 17 db ' ' db 'Binary',10,0 ten dd 10 SECTION .bss h resd 1 num resd 1 width resd 1 SECTION .text global _start _start: call ReadDec ; read an unsigned integer mov [h],eax ; move the integer to n mov edx,hrule ; print the table header call WriteString mov edx,header call WriteString mov edx,hrule call WriteString .L0: cmp dword [h],0 ; while h >= 0 do je .L5 call ReadInt ; read a signed 32-bit integer mov dword [num], eax ; save a copy in num mov edx,spacer1 call WriteString ; determine the width of the input num mov dword [width],1 mov eax,[num] .L1: cdq ; convert from dword to qword idiv dword [ten] ; signed division by 10 cmp eax,0 ; if the quotient is 0, we're done je .L2 inc dword [width] ; else increment the width jmp .L1 .L2: mov ecx,10 ; insert enough spaces to right-justify sub ecx,[width] ; num .L3: cmp ecx,0 je .L4 mov al,' ' call WriteChar dec ecx jmp .L3 .L4: mov eax,[num] call WriteInt mov edx,spacer2 call WriteString call PrintBinary mov al,10 call WriteChar dec dword [h] jmp .L0 ; end while .L5: mov edx,hrule ; print the table footer call WriteString Exit {0}