我不明白为什么我的程序无法正常工作
在我的程序中,我要取一个可变数字 并将其放在数据段中,然后我要显示 该数字使用ah,02h函数,但问题是显示不正确 数据段中的内容。这里是 我在数据段中有18 44我反编译
mov si,offset result
如果si现在指向18,我使用:
mov al,byte ptr[si] ; now al have 18
xor ah,ah
aam ; now ax is 0204
add ah,30h ; to change to hex
add al,30h
现在斧头是3234,现在我将移动ax to bx and display it
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
现在应该显示24,但显示时会出错
我也用je指令循环 左边的数字
inc si
我要44
aam
0608 = ax
add ah,30h
add al,30h
ax = 3638再次移动到bx
当我使用ah,02h int 21显示时 应该给68
一般它应该给出2468,但是现在它没有给出该值
在我使用的主要过程中
mov ax,@data
mov ds,ax
mov es,ax
mov ss,ax
我也使程序模型变大了但没变 该程序有300行,如果我将var 2改为2468(1844) 如果我使var两位数字,它将打印31,例如11,如果是1234,则打印3232,如果使 313131。在bx中成功设置了数字,显示期间发生错误 但是如果我在bx中移动一个特定的数字,则它可以单独正常工作。
我打开调试,并在bx中设置了编号 正确,如果它在bx中是32,则应打印2,但给出另一个值 都是一样的。如果数字增加,则会增加
2 32 1 32
3 32
11 3232
111 323232看起来像这样
aam
add ah,30h
add al,30h
xor bx,bx
xor dx,dx
mov bx,ax
mov dl,bh`
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
inc si
jmp .display
这里有完整的代码
.model large
.stack 4096
.data
msg1 db 10,13,'------>$'
msg2 db 10,13,'------->$'
first_n db 13
db ?
db 10,13, 13 dup(' ')
sec_n db 13
db ?
db 10,13, 13 dup (' ')
total_sp db ?
carry db ?
result db ?
db 7 dup(' ')
resultm db 10,13,"the sum is: $"
printable db 13 dup (' ')
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
mov ss,ax
mov dx,offset msg1
mov ah,09h
int 21h
mov dx,offset first_n
mov ah,0ah
int 21h
mov dx,offset msg2
mov ah,09h
int 21h
mov dx,offset sec_n
mov ah,0ah
int 21h
;___________________________________________________
mov bx,1
mov al,byte ptr [first_n+bx]
mov ah,byte ptr[sec_n+bx]
jmp which_great
take_1:
mov total_sp,al
jmp .start
which_great:
cmp al,ah
jge take_1
mov total_sp,ah
;____________________________________________
.start:
xor ax,ax
xor bx,bx
xor dx,dx
mov al,total_sp
mov bx,2
div bx
jmp paritychek
add_sp:
cmp al,0
je dontadd
jmp add1
dontadd:
mov al,1
jmp endpchek
add1:
add al,1
jmp endpchek
paritychek:
cmp dx,0
jne add_sp ; if it is odd add 1 to the result ,for space reserve
endpchek:
mov result,al
xor dx,dx
xor ax,ax
xor bx,bx
;------------------------------------------------------------------------------
; the next procedure take a inserted string for
; first number use si and for second used bx to
; access data segment puts numbers in al and dl
; add them together and store.
; carry byte is putted in a carry for next byte
;------------ - - - - - - - ------------------------ - - - - - - - -------------------
begin1:
mov si,offset first_n
inc si ;point to a number intered by user
xor cx,cx ;clear everything from cx
mov cl,[si] ;move digits enter by user to cl
add si,cx ;add a digit enterd by user to itself now si point
;to last digit
theres1st:
xor ax,ax
cmp si,offset first_n+1
je nodigit
mov al,byte ptr[si]
dec si
cmp si ,offset first_n+1
je nodigit
theres2nd:
mov ah,byte ptr[si]
sub al,30h
sub ah,30h
aad
dec si
xor cx,cx
jmp num2test
nodigit:
cmp al,0
je l139
sub al,30h
l139:
switch_first:
xor cx,cx
mov cl,1
push cx
num2test:
cmp ch,01
je startadd
cmp bx,0
je begin2
jmp .theres1st
jmp begin2
;--------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; for second number taking digits
;-- --- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin2:
mov bx,offset sec_n
inc bx
xor cx,cx
mov cl,[bx]
add bx,cx
.theres1st:
xor dx,dx
cmp bx,offset sec_n+1
je .nodigit
mov dl,byte ptr [bx]
dec bx
cmp bx,offset sec_n+1
je .nodigit
.theres2nd:
mov dh,byte ptr[bx]
sub dl,30h
sub dh,30h
push ax
mov ax,dx
aad
mov dx,ax
pop ax
dec bx
jmp startadd
.nodigit:
cmp dl,0
je l193
sub dl,30h
l193:
pop cx
switch_second:
mov ch,01 ;if al 1 no first left if ah 1no second left
push cx
;___________________________________________________
;-----------------------------------------------------------------------------------------
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -
;adding the two numbers from ax and dx
;
;- - - - - - - - - - - - - - - - - - - - - - - --- - - - -- - - - - - - - - - - - -
startadd:
add ax,dx
add al,carry
mov carry,ah
xor ah,ah
cmp di,0 ;is di register have offset loaded to it
jne put_it ; if not jump to put_it procedure
mov di,offset result
mov cl,byte ptr[di]
xor ch,ch
add di,cx
put_it:
cmp di,offset result
je l235
mov byte ptr[di],al
dec di
xor cx,cx
l235:
pop cx
;----------------------
label_end:
cmp cx,0101h
je last_carry
jmp theres1st
last_carry:
nop
;______________________________________________
;/ time for display ****** **** /
;/---------------------------------------------------------------/
mov dx,offset resultm
mov ah,09h
int 21h
xor ax,ax
xor dx,dx
xor bx,bx
xor cx,cx
xor si,si
xor di,di
mov di,offset result
mov cl,[di]
add di,cx
mov dl,carry
cmp dl,0
je no_carryn
add dl,30h
mov ah,02h
int 21h
no_carryn:
mov si,offset result+1
.display:
cmp si,di
jng dumpit
jmp final_p
dumpit:
xor ax,ax
mov al, byte ptr[si]
aam
add ah,30h
add al,30h
xor dx,dx
xor bx,bx
ldisp:
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
inc si
jmp .display
final_p:
nop
mov ah,4ch
int 21h
main endp
end main