打印输出错误与assymble代码
问题描述:
我对我的代码打印,我没能解决问题..打印输出错误与assymble代码
我的程序很简单敏锐地这是对如何绘制简单的线性方程实践
x在-2和2之间为常数
并且用户必须在线性等式y = ax + b中输入一个& b。
一个& b的签约用户还必须输入符号
,程序必须给5对(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.
}
和感谢提前的帮助:)
答
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
没有消息能够被正确打印.. – 2015-04-05 18:25:53
实际的问题是在最后结果时,我想打印Ÿ – 2015-04-05 18:26:50
见编辑答案。同样的问题4次。 – 2015-04-05 18:29:52