Assembly Masm 16位将Ascii转换为字节

Assembly Masm 16位将Ascii转换为字节,assembly,ascii,masm,x86-16,Assembly,Ascii,Masm,X86 16,我是汇编语言的初学者,必须尽快找到解决方案。 问题是我必须从这个人身上读取一个数字(3位数字),将其转换成一个整数,并将其与两个值进行比较。 问题是,在转换比较后,有时结果是正确的,有时则不是 pile segment para stack 'pile' db 256 dup (0) pile ends data segment ageper db 4,5 dup(0) bigg db 13,10,"bigger than 146 ",13,10,"$" lesss db 13,10,

我是汇编语言的初学者,必须尽快找到解决方案。
问题是我必须从这个人身上读取一个数字(3位数字),将其转换成一个整数,并将其与两个值进行比较。
问题是,在转换比较后,有时结果是正确的,有时则不是

pile segment para stack 'pile'
    db 256 dup (0)
pile ends

data segment
ageper db 4,5 dup(0)
bigg db 13,10,"bigger than 146 ",13,10,"$"
lesss db 13,10,"less than 0 ",13,10,"$"
right db 13,10,"correct number 123 ",13,10,"$"
theint db 0


exacnumber db 123
data ends

code segment
main proc far

    assume cs:code
    assume ds:data
    assume ss:pile
    mov ax,data
    mov ds,ax

    mov ah,0ah
    lea dx,ageper
    int 21h

    mov ch,0
    cmp ageper[4],0
    jz phase2
    mov ah,ageper[4]
    sub ah,48
    add theint,ah
    phase2:
    mov cl,10
    cmp ageper[3],0
    jz phase3
    mov ah,ageper[3]
    sub ah,48
    mov al,ah
    mul cl
    add theint,al
    phase3:
    mov cl,100
    cmp ageper[2],0
    jz phase4
    mov ah,ageper[2]
    sub ah,48
    mov al,ah
    mul cl
    add theint,al

    phase4:
    cmp theint,123
    je yes
    cmp theint,130
    jg big
    cmp theint,0
    jl less
    jmp ending


    big:
    mov ah,09h
    lea dx,bigg
    int 21h
    jmp ending

    yes:
    mov ah,09h
    lea dx,right
    int 21h
    jmp ending

    less:
    mov ah,09h
    lea dx,lesss
    int 21h


    ending:
    mov ageper,20
    mov ageper[1],20

    mov ah,02
    lea dx,theint
    int 21h

    mov ah,4ch
    int 21h
main endp
code ends
    end main
您的程序执行不稳定,因为您没有正确解释输入
从DOS接收的简单3位输入不需要像您那样检查数字0。只需删除这3个
cmp
jz


另一个小的逻辑错误是,当数字大于130时,您将其报告为大于146


这些指示毫无意义


在这里,您对正确使用DOS函数感到困惑。函数02h使用
DL
寄存器,函数09h使用
DX
寄存器。请查一下你的手册


要解决@Michael报告的问题(要处理256到999之间的3位数字),请将theint变量定义为word并添加到其中,如下所示:

theint dw 0

mov ch, 0
mov cl, ageper[4]
sub cl, 48
mov theint, cx       <<< Use MOV the first time!
phase2:
mov cl, 10
mov al, ageper[3]
sub al, 48
mul cl
add theint, ax       <<< Add AX in stead of AH
phase3:
mov cl, 100
mov al, ageper[2]
sub al, 48
mul cl
add theint, ax       <<< Add AX in stead of AH
intdw0
mov-ch,0
mov cl,ageper[4]
副cl,48

mov theint,cx您正在使用一个字节来保存转换后的整数。一个无符号字节只能表示0-255范围内的值。谢谢你,最后我需要读取一个无符号的输入,这样这个字节工作得很好,并且是整数范围。谢谢你的帮助!!问题是,int的值是无符号的,所以当我切换到jg的jainstead时,问题已经解决了。我也用0取下了cmp,然后程序开始工作,对于要测试的20个,最后教授没有给我们任何手册,只是让我们上网看看。。。在另一件事上我可能需要你的帮助,再次感谢你的帮助
mov ageper,20
mov ageper[1],20
mov ah,02
lea dx,theint
int 21h
theint dw 0

mov ch, 0
mov cl, ageper[4]
sub cl, 48
mov theint, cx       <<< Use MOV the first time!
phase2:
mov cl, 10
mov al, ageper[3]
sub al, 48
mul cl
add theint, ax       <<< Add AX in stead of AH
phase3:
mov cl, 100
mov al, ageper[2]
sub al, 48
mul cl
add theint, ax       <<< Add AX in stead of AH