Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- .data
- input_prompt db 'Iveskite sesioliktaini skaiciu: $'
- help_text db 'Programa konvertuoja ivesta sesioliktaini skaiciu i dvejetaini.$'
- invalid_input db 'Neteisinga ivestis!$'
- new_line db 13,10,'$'
- result db 'Dvejetainis atitikmuo: $'
- input db 100, 0, dup(0)
- .code
- program:
- ;load ds
- mov ax,@data
- mov ds,ax
- ;check if help text needs to be printed
- mov bx,81h
- argv:
- mov ax,es:[bx]
- inc bx
- cmp al,13
- je print_input_prompt
- cmp al,' '
- je argv
- cmp ax,'?/'
- jne argv
- mov ax,es:[bx]
- cmp ah,13
- je help
- cmp al,' '
- je help
- jmp print_input_prompt
- ;print help text
- help:
- mov ah,9h
- mov dx,offset help_text
- int 21h
- jmp finish
- ;print input prompt
- print_input_prompt:
- mov dx,offset input_prompt
- mov ah,9h
- int 21h
- ;ask user for input
- collect_input:
- mov ah,0Ah
- mov dx,offset input
- int 21h
- ;move carret to a new line
- mov ah,9h
- mov dx,offset new_line
- int 21h
- ;validates input and prints error if input is invalid
- mov bx,offset input
- add bx,2
- validate_input:
- mov ax,ds:[bx]
- inc bx
- ;if not end of input
- cmp al,13
- je print_result_msg
- ;if number
- cmp al,30h
- jb error
- cmp al,39h
- jbe validate_input
- ;if letter
- cmp al,41h
- jb error
- cmp al,46h
- jbe validate_input
- jmp error
- ;print error msg
- error:
- mov dx,offset invalid_input
- mov ah,9h
- int 21h
- jmp finish
- ;print result msg
- print_result_msg:
- mov dx,offset result
- mov ah,9h
- int 21h
- ;convert hex to bin
- mov bx,offset input
- add bx,2h
- convert:
- mov ax,ds:[bx]
- inc bx
- cmp al,13
- je finish
- cmp al,39h
- jbe convert_number
- jmp convert_letter
- ;convert number character in al to number
- convert_number:
- sub al,30h
- jmp print_binary
- ;convert letter to number
- convert_letter:
- sub al,55d
- jmp print_binary
- print_binary:
- mov ch,4;how many chars will be shown
- mov cl,3;how many rotates will be made
- process:
- push ax
- ;convert bit to char
- mov dl,al
- ror dl,cl
- and dl,01
- add dl,30h
- ;print 0 or 1
- mov ah, 02h
- int 21h
- ;proceed if ch
- pop ax
- dec cl
- dec ch
- jnz process
- ;space after every 4 bits
- mov dl,' '
- mov ah,2h
- int 21h
- jmp convert
- ;finish program
- finish:
- mov ax,4c00h
- int 21h
- end program
Add Comment
Please, Sign In to add comment