程序显示随机符号而不是文本

时间:2014-03-29 21:32:32

标签: assembly x86

我在大会上写了这个程序。我正在使用MALM编译器8086处理器。此程序旨在显示3条消息并获取3个值。我刚开始并且有问题找出已经完成的错误。

dane1 segment
a   db 30,0
    db 31 dup(?)
    db '$'
d   db ?
    db'$'
b   db 30,0
    db 31 dup(?)
    db '$'
tx1 db "Enter the first number (max 30 characters) :",10,13,"$"
    db ?
tx2 db "Enter the symbol *,+,-,/: ",10,13,"$"
    db ?
tx3 db "Enter the second number (max 30 characters): ",10,13,"$"
    db ?
nline db 10,13,"$"
    db ?
dane1 ends
code1 segment
start1:
    mov sp,offset wstosu    ;stack initzialization
    mov ax,seg wstosu
    mov ss,ax

    ;showing the first message
    mov dx, offset tx1
    mov ax, seg tx1
    mov ds, ax
    mov ah,9
    int 21h

    ;getting input
    mov ax, seg dane1
    mov ds,ax
    mov dx,offset a
    mov ah,0AH

    ;loading input to a
    mov bh,0 
    mov bl,byte ptr ds:[a+1]
    add bx,offset a+2
    mov byte ptr ds:[bx],'$'
    int 21h

    mov dx, offset nline
    mov ax, seg nline
    mov ds,ax
    mov ah,9
    int 21h

    ;showing the second message
    mov dx, offset tx2
    mov ax, seg tx2
    mov ds, ax
    mov ah,9
    int 21h

    ;getting input
    mov ax, seg dane1
    mov ds, ax
    mov dx, offset d
    mov ah, 0AH

    ;loading input to d
    mov bh, 0
    mov bl, byte ptr ds:[d+1]
    add bx, offset d+2
    mov byte ptr ds:[bx],'$'
    int 21h

    ;new line
    mov dx, offset nline
    mov ax, seg nline
    mov ds, ax
    mov ah, 9
    int 21h

    ;showing third message
    mov dx, offset tx3
    mov ax, seg tx3
    mov ds, ax
    mov ah,9
    int 21h

    mov ah,4ch
    int 21h


code1 ends
stos1 segment stack
    dw 200 dup(?)
wstosu  dw ?
stos1 ends
end start1

EDIT1: 我将代码更改为@Micheal建议但在我尝试显示tx2时仍然获得随机符号。

EDIT2: 我设法以某种方式显示消息而不是随机符号,但现在程序不等待第二次输入。我会很高兴得到任何帮助。

1 个答案:

答案 0 :(得分:1)

您假设寄存器仍保留已更改的值:

mov ax,seg dane1        
mov ds, ax
mov dx, offset tx1
mov ah, 09h   <-- Here you're altering the high 8 bits of ax
int 21h       <-- int 21h / function 9h will destroy al

mov ds,ax     <-- Here you assume that ax still holds seg dane1, which it doesn't

您的代码中可能存在其他问题,这只是最明显的问题。