Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack
- .code
- main proc
- ;call read_char
- call cr_lf
- ;call read_decimal
- call read_binary
- call write_binary
- call cr_lf
- call write_hexa
- call cr_lf
- call write_decimal
- mov AH, 4ch
- int 21h
- main endp
- read_char proc
- push AX
- mov AH,1h ;inputkod
- int 21h
- mov DL, AL
- pop AX
- ret
- read_char endp
- write_char proc
- push AX
- mov AH,2
- int 21h
- pop AX
- ret
- write_char endp
- write_binary proc
- push BX
- push CX
- push DX
- mov BL, DL ;a DLt fogjuk alakitgatni, igy nem art lementeni a BLbe
- mov CX, 8 ;counter regiszter, 8x akarjuk a loopot
- binary_digit:
- xor DL, DL ;a kizaro vaggyal ki tudjuk nullazni a regisztert, hiszen onmagaval alkalmazva 0z
- rcl BL, 1 ;1-el valo rotalas mukodik konstansal, ha tobbet szeretnenk akkor a masodik param is regiszter kene h legyen
- adc DL, '0' ;add (carryvel) DL + 48 + carry
- call write_char
- loop binary_digit
- pop DX
- pop CX
- pop BX
- ret
- write_binary endp
- CR equ 13
- LF equ 10
- cr_lf proc
- push dx
- mov DL, CR
- call write_char
- mov DL, LF
- call write_char
- pop dx
- ret
- cr_lf endp
- write_hexa proc
- push cx
- push dx
- mov DH, DL
- mov CL, 4
- SHR DL, CL
- call write_hexa_digit
- mov DL, DH
- AND DL, 0FH
- call write_hexa_digit
- pop DX
- pop CX
- RET
- write_hexa endp
- write_hexa_digit proc
- push DX
- CMP DL, 10
- JB no_hexa_digit
- ADD DL, 'A' - '0' - 10
- no_hexa_digit:
- ADD DL, '0'
- call write_char
- pop DX
- RET
- write_hexa_digit endp
- write_decimal proc
- push AX
- push CX
- push DX
- push SI
- xor DH, DH
- mov AX, DX
- mov SI, 10
- xor CX, CX
- decimal_non_zero:
- xor DX, DX
- DIV SI
- push DX
- INC CX
- or AX, AX
- JNZ decimal_non_zero
- decimal_loop:
- pop DX
- call write_hexa_digit
- loop decimal_loop
- pop SI
- pop DX
- pop CX
- pop AX
- ret
- write_decimal endp
- read_decimal proc
- push ax
- push bx
- mov bl, 10
- xor ax, ax
- r_d_new:
- call read_char
- cmp dl, cr
- je r_d_end
- mul bl
- sub dl,'0'
- add al, dl
- jmp r_d_new
- r_d_end:
- mov dl, al
- pop ax
- pop ax
- ret
- read_decimal endp
- read_binary proc
- push ax
- xor ax,ax
- r_b_new:
- call read_char
- cmp dl,cr
- je r_b_end
- sub dl, '0'
- sal al, 1
- add al, dl
- jmp r_b_new
- r_b_end:
- mov dl,al
- pop ax
- ret
- read_binary endp
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement