如何修复x86 Turbo汇编语言的输出 [英] how to fix the output for x86 turbo assembly language
问题描述
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
UserName db "Name: $"
CLRF db 10,13,"$"
inputName db 24 dup ("$")
CurYear db "Current Year: $"
inputCurrentYear dw 8 dup ("$")
BirYear db "Birth Year: $"
inputBirthYear dw 8 dup ("$")
outputName db "Hello, $"
outputAge db "Your age is $"
currentYearH1 db "$"
currentYearH2 db "$"
birthYearH1 db "$"
birthYearH2 db "$"
answer1 dw "$"
answer2 dw "$"
.code
BEGIN:
;open bracket
mov ax,@data
mov ds,ax
mov es,ax
mov al,03h
mov ah, 00h
int 10h
lea dx,CLRF
mov ah,09h
int 21h
;username input
NameInput:
lea dx,UserName
mov ah, 09h
int 21h
mov inputName,21
lea dx,inputName
mov ah,0ah
int 21h
lea dx,CLRF
mov ah,09h
int 21h
;current year
CurrentYear:
lea dx,CurYear
mov ah,09h
int 21h
mov inputCurrentYear,05
lea dx,inputCurrentYear
;mov ax,dx
mov ah,0ah
int 21h
mov ax,inputCurrentYear
sub ax,3030h
xchg ah,al
aad
mov currentYearH1, al
mov ax,inputCurrentYear[4]
sub ax,3030h
xchg ah,al
aad
mov currentYearH2, al
lea dx,CLRF
mov ah,09h
int 21h
;birth year
BirthYear:
lea dx,BirYear
mov ah,09h
int 21h
mov inputBirthYear,05
lea dx,inputBirthYear
;mov bx,dx
mov ah,0ah
int 21h
mov ax, inputBirthYear[2]
sub ax,3030h
xchg ah,al
aad
mov birthYearH1,al
mov ax,inputBirthYear[4]
sub ax,3030h
xchg ah,al
aad
mov birthYearH2,al
lea dx,CLRF
mov ah,09h
int 21h
;lea dx,inputBirthYear
;mov ah,09h
;int 21h
lea dx,CLRF
mov ah,09h
int 21h
;subtraction
;lea ax,inputCurrentYear
;lea dx,inputBirthYear
;sub ax,dx
;mov [SI],ax
;lea dx,[SI]
;mov ah,09h
int 21h
;sub ax,3030h
Output:
lea dx, outputName
mov ah,09h
int 21h
lea dx, inputName
mov ah,09h
int 21h
lea dx,CLRF
mov ah,09h
int 21h
;lea ax,inputCurrentYear
;lea dx,inputBirthYear
;sub ax,dx
;mov difference,ax
lea dx,outputAge
mov ah,09h
int 21h
lea dx,CLRF
mov ah,09h
int 21h
lea dx,CLRF
mov ah,09h
int 21h
mov al,birthYearH2
sub currentYearH2,al
mov al,birthYearH1
sub currentYearH1,al
mov al,currentYearH2
aam
add ax,3030h
xchg ah,al
mov answer2,ax
mov al,currentYearH1
aam
add ax,3030h
xchg ah,al
mov answer1,ax
lea dx, answer1
mov ah,09h
int 21h
lea dx,answer2
mov ah,09h
int 21h
lea dx,CLRF
mov ah,09h
int 21h
mov ah,4ch
int 21h
end BEGIN
运行此代码时,输出中会出现随机符号,我想清理"我的输出.
When I run this code there are random symbols appearing with the output and I want to "clean up" my output.
推荐答案
Int 21h/0Ah
需要一个指向结构的指针,不是一个指向字符串的指针.您必须使用该字符串的最大长度来填充该结构的第一个字节.函数将使用输入字符串的实际长度填充第二个字节.字符串不会以 int 21h/09h
,但具有0Dh.因此,您需要更改该字符.
Int 21h/0Ah
expects a pointer to a structure, not a pointer to a string. The first byte of that structure must filled by you with the maximal length of the string. The second byte will be filled by the function with the real length of the inputted string. The string won't end with '$' as needed for int 21h/09h
, but with 0Dh. So you need to change that character.
我仅对inputName纠正了问题.其余的取决于您.
I corrected the issues only for inputName. The rest is up to you.
...
mov inputName,21
lea dx,inputName
mov ah,0ah
int 21h
; change 0Dh to '$'
xor bh,bh
mov bl, [inputName+1] ; length of string
mov byte [inputName+2+bx], '$' ; store end-of-string-character
...
lea dx, outputName
mov ah,09h
int 21h
lea dx, [inputName+2] ; pointer to string
mov ah,09h
int 21h
...
这篇关于如何修复x86 Turbo汇编语言的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!