Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Progr segment
- assume cs:Progr, ds:dane, ss:stosik
- start: mov ax,dane
- mov ds,ax
- mov ax,stosik
- mov ss,ax
- mov sp,offset szczyt
- next_digit:
- ; get char from keyboard
- ; into AL:
- MOV AH, 00h
- INT 16h
- ; and print it:
- MOV AH, 0Eh
- INT 10h
- ; check for MINUS:
- CMP AL, '-'
- JE set_minus
- ; check for ENTER key:
- CMP AL, 13 ; carriage return?
- JNE not_cr
- JMP stop_input
- not_cr:
- jmp backspace_checked
- backspace_checked:
- ; allow only digits:
- CMP AL, '0'
- JAE ok_AE_0
- ok_AE_0:
- CMP AL, '9'
- JBE ok_digit
- ;todo skok że nie jest cyfrą
- ok_digit:
- ; multiply CX by 10 (first time the result is zero)
- PUSH AX
- MOV AX, CX
- MUL CS:ten ; DX:AX = AX*10
- MOV CX, AX
- POP AX
- ; convert from ASCII code:
- SUB AL, 30h
- ; add AL to CX:
- MOV AH, 0
- ADD CX, AX
- ;todo jump if the number is too big.
- JMP next_digit
- set_minus:
- MOV CS:make_minus, 1
- JMP next_digit
- stop_input:
- ; check flag:
- CMP CS:make_minus, 0
- JE print_hex
- NEG CX
- jmp print_hex
- print_hex:
- mov bl, cl ;in cl is stored number
- mov cx, 4
- .print_digit:
- rol bx, 4 ; move the currently left-most digit into the least significant 4 bits
- mov dx,bx
- and dx, 15 ; isolate the hex digit we want to print
- add dx,30h ; and convert it into a character..
- cmp dx,'9' ; ...
- jbe .ok ; ...
- add dx,7 ; ... (for 'A'..'F')
- .ok: ; ...
- mov ah,2h ; INT 21H / AH=2: write character to stdout
- int 21h
- loop .print_digit
- MOV AH, 4CH
- MOV AL, 01 ;your return code.
- INT 21H
- Progr ends
- dane segment
- make_minus DB ? ; used as a flag.
- ten DW 10 ; used as multiplier.
- dane ends
- stosik segment
- dw 100h dup(0)
- szczyt Label word
- stosik ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement