how to fix the output for x86 turbo assembly language

别来无恙 提交于 2019-12-04 06:38:49

问题


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.


回答1:


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.

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

    ...



回答2:


Note: The format of DOS input buffer+2 contains the actual characters read, including the final carriage return.

RBIL->inter61b.zip->INTERRUP.F
--------D-210A-------------------------------
INT 21 - DOS 1+ - BUFFERED INPUT
AH = 0Ah
DS:DX -> buffer (see #01344)
Return: buffer filled with user input
Notes:  ^C/^Break are checked, and INT 23 is called if either detected
reads from standard input, which may be redirected under DOS 2+
if the maximum buffer size (see #01344) is set to 00h, this call returns
  immediately without reading any input
SeeAlso: AH=0Ch,INT 2F/AX=4810h

Format of DOS input buffer:
Offset  Size    Description (Table 01344)
 00h    BYTE    maximum characters buffer can hold
 01h    BYTE    (call) number of chars from last input which may be recalled
    (ret) number of characters actually read, excluding CR
 02h  N BYTEs   actual characters read, including the final carriage return
--------K-210A00-----------------------------


来源:https://stackoverflow.com/questions/24816507/how-to-fix-the-output-for-x86-turbo-assembly-language

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