mahdad_12
جمعه 03 دی 1389, 21:56 عصر
|برنامه که یک عدد از کاربر دریافت میکنه با استفاده از بازگشتی از عدد خوانده شده تا عدد یک را نمایش دهد
من این برنامه رو نوشتم ولی خطا میده
لطفا کمک کنید
**************************
sseg segment stack
dw 512 dup(?)
sseg ends
datasg segment para 'data'
prompt db 'Enter a number :',0ah,0dh,"$"
rowcol dw 0
string db 8 dup(' '),"$"
buffer db 20 dup(' ')
num dw ?
datasg ends
codesg segment para 'code'
main proc far
assume ds:datasg, cs:codesg
push ds
push 0
mov ax,datasg
mov ds,ax
mov ah,6h ;clean screen
mov al,25
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
int 10h
mov byte ptr rowcol+1 , 5
mov byte ptr rowcol,30
loop1:
push rowcol
;;;;;;;;;;;;;;;;;;;;;;;call move_cursor
push bp
mov bp,sp
push ax
push bx
push dx
pushf
mov ah,2h
mov bx,word ptr [bp+06]
mov dh,bh
mov dl,bl
mov bx,0
int 10h
popf
pop dx
pop bx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;;;
push offset prompt
;;;;;;;;;;;;;;;;;;; call disp_message
push bp
mov bp,sp
push ax
push dx
mov dx,[bp+06]
mov ah,9h
int 21h
pop dx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;
push offset buffer
call get_num
mov num,ax
cmp ax,0
jl loop1
mov byte ptr rowcol+1,0
mov byte ptr rowcol,0
mov ah,6h ;clean screen
mov al,25
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
int 10h
push rowcol
;;;;;;;;;;;;;;;;;;;;;;call move_cursor
push bp
mov bp,sp
push ax
push bx
push dx
pushf
mov ah,2h
mov bx,word ptr [bp+06]
mov dh,bh
mov dl,bl
mov bx,0
int 10h
popf
pop dx
pop bx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;
mov ax,num
push ax
call _display
add sp,2
ret
main endp
_display proc
push bp
mov bp,sp
cmp word ptr [bp+4],0
je return
mov ax,[bp+4]
mov num,ax
push ax
push offset string
;;;;;;;;;;;;;;;;convert_number_string
push bp
mov bp,sp
mov ax,word ptr [bp+08]
mov si,word ptr [bp+06]
add si,5
mov bh,' '
cmp ax,0
jge setup
mov bh,'-'
neg ax
setup:
mov cx,10
divloop:
mov dx,0
div cx
add dl,30h
mov [si],dl
dec si
cmp ax,0
jne divloop
mov cl,bh
mov [si],cl
pop bp
ret 4
;;;;;;;;;;;;;;;;;;end_convert_number_string
push offset string
;;;;;;;;;;;;;;;;;;;;;call disp_message
push bp
mov bp,sp
push ax
push dx
mov dx,[bp+06]
mov ah,9h
int 21h
pop dx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ax,num
dec ax
push ax
call _display
add sp,2
return:
pop bp
ret
_display endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_num proc
push bp
mov bp,sp
mov ah,3fh
mov dx,[bp+06]
mov bx,0000h
mov cx,8
int 21h
mov si,dx
while_blank:
cmp byte ptr [bx],' '
jne end_while_blank
inc bx
jmp while_blank
end_while_blank:
mov bl,1
cmp byte ptr [si],'+'
je skip_sign
cmp byte ptr [si],'-'
jne save_sign
mov bl,-1
skip_sign:
inc si
save_sign:
mov ax,0
mov bh,0
while_digit:
cmp byte ptr [si],'0'
jl end_while_digit
cmp byte ptr [si],'9'
jg end_while_digit
mov cx,10
mul cx
mov cl,[si]
and cx,000fh
add ax,cx
inc bh
inc si
jmp while_digit
end_while_digit:
cmp bl,1
je exit1
neg ax
exit1:
pop bp
ret 2
;;;;;;;;;;end get_num
get_num endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
codesg ends
end main
**************************
من این برنامه رو نوشتم ولی خطا میده
لطفا کمک کنید
**************************
sseg segment stack
dw 512 dup(?)
sseg ends
datasg segment para 'data'
prompt db 'Enter a number :',0ah,0dh,"$"
rowcol dw 0
string db 8 dup(' '),"$"
buffer db 20 dup(' ')
num dw ?
datasg ends
codesg segment para 'code'
main proc far
assume ds:datasg, cs:codesg
push ds
push 0
mov ax,datasg
mov ds,ax
mov ah,6h ;clean screen
mov al,25
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
int 10h
mov byte ptr rowcol+1 , 5
mov byte ptr rowcol,30
loop1:
push rowcol
;;;;;;;;;;;;;;;;;;;;;;;call move_cursor
push bp
mov bp,sp
push ax
push bx
push dx
pushf
mov ah,2h
mov bx,word ptr [bp+06]
mov dh,bh
mov dl,bl
mov bx,0
int 10h
popf
pop dx
pop bx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;;;
push offset prompt
;;;;;;;;;;;;;;;;;;; call disp_message
push bp
mov bp,sp
push ax
push dx
mov dx,[bp+06]
mov ah,9h
int 21h
pop dx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;
push offset buffer
call get_num
mov num,ax
cmp ax,0
jl loop1
mov byte ptr rowcol+1,0
mov byte ptr rowcol,0
mov ah,6h ;clean screen
mov al,25
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
int 10h
push rowcol
;;;;;;;;;;;;;;;;;;;;;;call move_cursor
push bp
mov bp,sp
push ax
push bx
push dx
pushf
mov ah,2h
mov bx,word ptr [bp+06]
mov dh,bh
mov dl,bl
mov bx,0
int 10h
popf
pop dx
pop bx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;
mov ax,num
push ax
call _display
add sp,2
ret
main endp
_display proc
push bp
mov bp,sp
cmp word ptr [bp+4],0
je return
mov ax,[bp+4]
mov num,ax
push ax
push offset string
;;;;;;;;;;;;;;;;convert_number_string
push bp
mov bp,sp
mov ax,word ptr [bp+08]
mov si,word ptr [bp+06]
add si,5
mov bh,' '
cmp ax,0
jge setup
mov bh,'-'
neg ax
setup:
mov cx,10
divloop:
mov dx,0
div cx
add dl,30h
mov [si],dl
dec si
cmp ax,0
jne divloop
mov cl,bh
mov [si],cl
pop bp
ret 4
;;;;;;;;;;;;;;;;;;end_convert_number_string
push offset string
;;;;;;;;;;;;;;;;;;;;;call disp_message
push bp
mov bp,sp
push ax
push dx
mov dx,[bp+06]
mov ah,9h
int 21h
pop dx
pop ax
pop bp
ret 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ax,num
dec ax
push ax
call _display
add sp,2
return:
pop bp
ret
_display endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_num proc
push bp
mov bp,sp
mov ah,3fh
mov dx,[bp+06]
mov bx,0000h
mov cx,8
int 21h
mov si,dx
while_blank:
cmp byte ptr [bx],' '
jne end_while_blank
inc bx
jmp while_blank
end_while_blank:
mov bl,1
cmp byte ptr [si],'+'
je skip_sign
cmp byte ptr [si],'-'
jne save_sign
mov bl,-1
skip_sign:
inc si
save_sign:
mov ax,0
mov bh,0
while_digit:
cmp byte ptr [si],'0'
jl end_while_digit
cmp byte ptr [si],'9'
jg end_while_digit
mov cx,10
mul cx
mov cl,[si]
and cx,000fh
add ax,cx
inc bh
inc si
jmp while_digit
end_while_digit:
cmp bl,1
je exit1
neg ax
exit1:
pop bp
ret 2
;;;;;;;;;;end get_num
get_num endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
codesg ends
end main
**************************