Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DATA SEGMENT
- Buffer DB 7, '?', 6 dup('?'), '$'
- Error DB 'Error$'
- Message1 DB 'Enter number: $'
- Message2 DB 'Press to show number..', 0Dh, 0Ah, '$'
- DATA ENDS
- CODE SEGMENT
- ASSUME CS:CODE, DS:DATA
- Start:
- mov ax,DATA
- mov ds,ax
- mov dx,offset Message1
- mov ah, 9
- int 21h
- call Get_integer
- cmp di,2
- jz er
- push ax
- mov dx,offset Message2
- mov ah, 9
- int 21h
- mov ah, 10h
- int 16h
- pop ax
- call Print_integer
- mov ah, 4Ch
- int 21h
- er:
- mov dx, offset Error
- mov ah,09
- int 21h
- mov ah, 4Ch
- int 21h
- Get_integer proc
- mov ah,0ah
- xor di,di
- mov dx,offset Buffer
- int 21h
- mov dl,0ah
- mov ah,02
- int 21h
- mov si,offset Buffer+2
- cmp byte ptr [si],"+"
- jz p1
- cmp byte ptr [si],"-"
- jnz p2
- mov di,1
- p1:
- inc si
- p2:
- xor ax,ax
- mov bx,10
- p3:
- mov cl,[si]
- cmp cl,0dh
- jz endin
- cmp cl,'0'
- jb erg
- cmp cl,'9'
- ja erg
- sub cl,'0'
- mul bx
- add ax,cx
- jc erg
- cmp ax, 8000h
- ja erg
- inc si
- jmp p3
- erg:
- mov di,2
- ret
- endin:
- cmp di,1
- jnz p4
- neg ax
- p4:
- ret
- Get_integer endp
- Print_integer proc
- mov bx, ax
- or bx, bx
- jns ml
- mov al, '-'
- int 29h
- neg bx
- ml:
- mov ax,bx
- xor cx,cx
- mov bx,10
- m2:
- xor dx,dx
- div bx
- add dl,'0'
- push dx
- inc cx
- test ax,ax
- jnz m2
- m3:
- pop ax
- int 29h
- loop m3
- ret
- Print_integer endp
- CODE ENDS
- END Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement