使用汇编代码打印错误

时间:2015-04-05 18:07:23

标签: assembly logic helper

我的代码上的打印有问题我无法解决..

我的程序非常简单,这是一种如何绘制简单线性方程式的实践

x在-2和2之间是常数

并且用户必须输入& b在线性方程y = ax + b。

a& b签名用户还必须输入标志

并且程序必须给出五对(y,x),但它对我不起作用

这是代码:

{

    ; multi-segment executable file template.

data segment
    ; add your data here!

    x   db -2,-1,0,1,2
    r1  dw 0,0,0,0,0
    r2  dw 0,0,0,0,0
    z1  dw 0,0,0,0,0
    z2  dw 0,0,0,0,0 
    a1  db 0 
    a2  db 0
    b1  db 0
    b2  db 0

    m1 db "This program will give u 5 pairs of result for the following eqn 'y=ax+b' where x is between -2 & 2.",0ah,0dh,"$",0ah,0dh
    m2 db 0ah,0dh,"Enter the sign of 'a',(+,-)",0ah,0dh,"$",0ah,0dh
    m3 db 0ah,0dh,"Enter 'a'",0ah,0dh,"$",0ah,0dh
    m4 db 0ah,0dh,"Enter the sign of 'b',(+,-)",0ah,0dh,"$",0ah,0dh
    m5 db 0ah,0dh,"Enter 'b'",0ah,0dh,"$",0ah,0dh  


ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here 

    lea dx, m1
    mov ah, 9
    int 21h

    lea dx, m2
    mov ah, 9
    int 21h

    xor ax,ax

    mov ah, 1     ;entering the sign of "a"
    int 21h        

    CMP al,'-'

    jnz next

    lea dx, m3
    mov ah, 9
    int 21h

    mov ah, 1     ;entering "a"
    int 21h
    sub al,30h

    neg al

    mov a1,al  
    xor ah,ah
    xor si,si
    mov cx,5

mul1: 

    mov al,a1

    imul x[si] 

    mov r1[si],ax   ;saving the result from multiplying "-ax" 

inc si    

    loop mul1 
    jmp b 


 next:  ;if "a" was pasitive 

    lea dx, m3
    mov ah, 9
    int 21h

    mov ah, 1     ;entering "a"
    int 21h
    sub al,30h

    mov a2,al

    xor ah,ah
    xor si,si
    mov cx,5 


mul2:

    mov al,a2

    imul x[si] 

    mov r2[si],ax   ;saving the result from multiplying "ax" 

    inc si    

    loop mul2  


 b: lea dx, m4
    mov ah, 9
    int 21h

    mov ah, 1     ;entering the sign of "b"
    int 21h 

    CMP al,'-'

    jnz next1

    lea dx, m5
    mov ah, 9
    int 21h 

    mov ah, 1     ;entering "b"
    int 21h
    sub al,30h 

    mov b1,al

    xor ah,ah
    xor si,si
    mov cx,5  

sub1:

    mov al,b1

    sub ax,r1[si] 

    mov z1[si],ax   ;saving the result from the op "ax-b" 

    inc si    

    loop sub1

    jmp print1    

next1: 

    lea dx, m5
    mov ah, 9
    int 21h 

    mov ah, 1     ;entering "b"
    int 21h 
    sub al,30h

    mov b2,al

    xor ah,ah
    xor si,si
    mov cx,5  

add1:

    mov al,b2 

    add ax,r2[si] 

    mov z2[si],ax   ;saving the result from the op "ax+b" 

    inc si    

    loop add1

    jmp print2

;printing the 5 pairs (x,y) when ax-b

print1:

    xor si,si
    mov cx,5

    print: 

    mov dl,0ah
    mov ah,2
    int 21h

    mov dl,0dh
    mov ah,2
    int 21h

    mov dl,'('
    mov ah,2
    int 21h


    lea dx,x[si]
    mov ah,9
    int 21h

    mov dl,","
    mov ah,2
    int 21h 

    lea dx,z1[si]
    mov ah,9
    int 21h

    mov dl,")"
    mov ah,2
    int 21h  

    mov dl,0ah
    mov ah,2
    int 21h

    mov dl,0dh
    mov ah,2
    int 21h

    inc si

    loop print
    jmp end1


print2: ;printing the 5 pairs (x,y) when ax+b  

    xor si,si
    mov cx,5 

    print11:

    mov dl,0ah
    mov ah,2
    int 21h

    mov dl,0dh
    mov ah,2
    int 21h 

    mov dl,"("
    mov ah,2
    int 21h


    lea dx,x[si]
    mov ah,9
    int 21h

    mov dl,","
    mov ah,2
    int 21h 

    lea dx,z2[si]
    mov ah,9
    int 21h

    mov dl,")"
    mov ah,2
    int 21h

    mov dl,0ah
    mov ah,2
    int 21h

    mov dl,0dh
    mov ah,2
    int 21h 

    inc si

    loop print11  

end1 :

    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends

end start ; set entry point and stop the assembler.

}

并感谢提前帮助:)

1 个答案:

答案 0 :(得分:0)

m1 db "This program will give u 5 pairs of result for the following eqn 'y=ax+b' where x is between -2 & 2.",0ah,0dh,"$",0ah,0dh
m2 db 0ah,0dh,"Enter the sign of 'a',(+,-)",0ah,0dh,"$",0ah,0dh
m3 db 0ah,0dh,"Enter 'a'",0ah,0dh,"$",0ah,0dh
m4 db 0ah,0dh,"Enter the sign of 'b',(+,-)",0ah,0dh,"$",0ah,0dh
m5 db 0ah,0dh,"Enter 'b'",0ah,0dh,"$",0ah,0dh  

在所有这些行中,最后的CRLF对将不会被打印,因为它在终止 $ 之后出现。这是你的PRINT问题吗?

m3 db 0ah,0dh,"Enter 'a'",0ah,0dh,0ah,0dh,"$"

这是一个问题。您将 x 定义为字节,将 r1 定义为字。您无法使用inc si来正确推进这两者。我建议您将 x 定义为单词并使用add si,2

mul1: 
 mov al,a1
 imul x[si] 
 mov r1[si],ax   ;saving the result from multiplying "-ax" 
 inc si    
 loop mul1