如何打印存储在变量中的整数 [英] How to print an integer stored in a variable

查看:20
本文介绍了如何打印存储在变量中的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 8086 汇编中有一个程序,它允许用户输入 2 位数字,将它们存储在一个变量中,然后打印出数字:

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

但是,无论何时我输入一个数字,例如 21,它都不会给我数字,而是给我该值的 ASCII 码.

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.

有人可以帮忙吗?!

推荐答案

但是,无论何时我输入一个数字,例如 21,它都不会给我数字,而是给我该值的 ASCII 码.

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.

如果您向程序输入(输入)一个由 2 位数字组成的数字,那么您还必须打印 2 位数字!目前您的代码只包含一个字符输出函数.

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.

  • 首先将 broj 中的数字除以 10,得到商(在 AL 中)和余数(在 AH 中).
  • 将商转换为字符(加 48)并打印出来.
  • 将余数转换为字符(加 48)并打印出来.
  • 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.

示例:

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

这篇关于如何打印存储在变量中的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆