Click here to Skip to main content
15,891,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to fuse an accepted 4-digit number, so far I have done the 2-digit number and got confuse fusing a 4-digit. Please help

Here my code:
ASM
mov ah,01
    int 21h
    sub al,30h
    mov bh,al

    mov ah,01
    int 21h
    sub al,30h
    mov bl,al

    call fuseIt


ASM
fuseIt PROC NEAR
    mov al,bh
    mov ah,0
    mov bl,10
    mul bl
    add al,bl
    RET
fuseIt ENDP
Posted
Comments
Sergey Alexandrovich Kryukov 25-Sep-13 0:26am    
Excuse for my ignorance, what does "fusing" mean?
—SA

1 solution

You need to create a loop and save the intermediate value each time. My assembler is extremely rusty (so there are probably some obvious mistakes) but I would think something like:

ASM
total: dw 0 ; a zeroised word

    xor ax,ax
    move total,ax     ; set total to zero
    mov cx,4          ; repeat 4 times
loop:
    mov ax,total      ; get the total
    mov bx,10       
    mul bx            ; multiply by 10
    mov total,ax      ; save new total
    mov ah,01
    int 21h           ; get next character
    sub al,30h        ; make it a digit. NB need to check in range 0 to 9.
    xor ah,ah         ; make it 16 bits
    add total,ax      ; add it to the total
    dec cx            ; decrement the counter
    jg  loop          ; repeat 4 times
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900