How to print an integer stored in a variable

偶尔善良 提交于 2019-12-11 07:46:42

问题


So I have a program in 8086 assembly that allows the user to enter 2 digits, store them in a variable and then print out the number:

data segment

    broj db ?


ends

stack segment

    dw 128 dup(0)

ends

code segment

    mov ax, data
    mov ds, ax
    mov es, ax

    mov ah, 1h
    int 21h

    sub al, 48d
    mov bl, 10d
    mul bl

    mov broj, al

    mov ah, 1h
    int 21h
    sub al, 48d
    add broj, al

    mov dl, broj
    sub dl, 48d
    mov ah, 2h
    int 21h

    mov ax, 4c00h
    int 21h

ends

However whenever I enter a number for example 21 it doesn't give me the number instead it gives me ASCII Code for that value.

Can anyone help?!


回答1:


However whenever I enter a number for example 21 it doesn't give me the number instead it gives me ASCII Code for that value.

If you feed (input) your program a number that consists of 2 digits, then you'll have to print also 2 digits! Currently your code contains just the one character output function.

  • First divide the number in broj by 10 giving a quotient (in AL) and a remainder (in AH).
  • Convert the quotient to character (Add 48) and print it.
  • Convert the remainder to character (Add 48) and print it.

Example:

mov al, broj
mov ah, 0
mov bl, 10
div bl
add ax, "00"
mov dx, ax
mov ah, 02h
int 21h
mov dl, dh
mov ah, 02h
int 21h


来源:https://stackoverflow.com/questions/53158760/how-to-print-an-integer-stored-in-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!