1

Helo there! I have a problem and i hope somebody can help me:) I need 2 macros: one to read and the other one to print a 32 bit integer I have a project for monday and I'm out of ideeas :( This is what I have until now:

Macro for reading:

reads macro x
local r, final 
push eax
push ebx
push edx
xor eax,eax
mov ebx, 10
r:
    mov ah,1h
    int 21h
    cmp al,0dh
je final
    sub al,48
    xor ah,ah
    mov edx,eax
    mov eax, x
    mul ebx
    add eax, edx
    mov x,eax
jmp r

final:
pop edx
pop ebx
pop eax
endm


Macro for printing: 


prints macro number
local decompose, printloop
push ax
push bx
push cx
push eax
push edx
mov bl, 10      ; need to divide by 10 to get the last digit
mov eax, number

mov cx,0
decompose:
    mov ah,0
    inc cx
    div bl          ; reminder stored in ah, quotient in al
    mov number,eax
    add edx,48      ; to convert to char
    push edx
    cmp number,0        ;the nr=0 means that the loop ends
    jnz decompose

printloop:  ;loops for as many times as counted before, in cx
    pop edx 
    mov ah,2h       ; prints whatever is in dl
    int 21h
loop printloop

    mov dl,' '      ; the space after a number
    mov ah,2h
    int 21h
pop edx
pop eax 
pop cx
pop bx
pop ax
endm prints
MANOJ GOPI
  • 1,279
  • 10
  • 31
Alex Torge
  • 31
  • 7
  • To get any help you need to describe in more detail where you are stuck. – mattias Jan 31 '15 at 10:07
  • 1
    Ad macro **reads**: you might not be aware that **mul ebx** puts the product in EDX:EAX. It is not good to use edx as a temporary storage. Choose other register. Ad macro **prints**: you will need to divide by 10^9, 10^8,...10^1 in order, and print the remainder. – vitsoft Jan 31 '15 at 11:22
  • I managed to redo another macro for print and that works too – Alex Torge Jan 31 '15 at 11:29

1 Answers1

1

These are the macros

For reading:

reads macro x,aux
local r, final
push eax
push ebx
push edx


mov ebx, 10
r:
    mov ah,1h
    int 21h
    cmp al,0dh
je final
cmp al,30h
jb r
cmp al,39h
ja r
    sub al,48
    xor ah,ah
    mov aux,eax
    mov eax, x
    mul ebx
    add eax,aux
    mov x,eax
jmp r

final:
pop edx
pop ebx
endm

For printing:

print macro number
local println, loopr

    push eax
    push edx
    push ebx
    push si
    mov cx,0
    mov eax,number
    mov ebx, 10
 loopr:  
    xor edx, edx
    div ebx         ; eax <- eax/10, edx <- eax % 10
    add dl, '0'     ; edx to ASCII
    push dx
    inc cx
    cmp eax, 0
    jnz loopr

    println:
    pop dx
    mov ah, 2h
    int 21h
    dec cx
    jnz println

    mov dl, 13d     ;Carriage Return
    mov ah, 2h
    int 21h
    mov dl, 10d     ;Line Feed
    mov ah, 2h
    int 21h

    pop si
    pop edx
    pop eax
   endm print
Alex Torge
  • 31
  • 7