Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Format regex input: [0-9A-F]{4}\s[0-9A-F]{4}\n
- ; Format regex output: [0-9A-F]{4,5}
- format MZ
- entry code_seg:start
- stack 256
- segment data_seg
- operand_1: db 0x0, 0x0
- operand_2: db 0x0, 0x0
- segment code_seg
- start:
- mov ax, data_seg
- mov ds, ax
- xor dx, dx
- read_input:
- mov ah, 0x0
- int 0x16
- if_space:
- cmp al, 0x20
- je handle_space ; replace if_space to nop
- ; enter
- cmp al, 0x0D
- je handle_enter
- ; decimal number
- cmp al, 0x30
- jl read_input ; skip because less than 1
- cmp al, 0x3A
- jl handle_dec
- ; hexadecimal number
- cmp al, 0x46
- jg read_input ; skip because greater than 'F'
- cmp al, 0x40
- jg handle_hex
- jmp read_input ; skip because unknown symbol
- ; input: al with byte
- ; output: concat_int
- handle_dec:
- call print_char
- sub al, 0x30
- call concat_int
- jmp read_input
- ; input: al with byte
- ; output: concat_int
- handle_hex:
- call print_char
- sub al, 0x37
- call concat_int
- jmp read_input
- ; input: al with hex int
- ; output: dx int concatenate with hex int
- ; change bx = 0x10
- concat_int:
- mov bx, 0x10
- xor ah, ah
- push ax
- ; appending zero
- mov ax, dx
- mul bx
- mov dx, ax
- ; concat dx number with al hex int
- pop ax
- add dx, ax
- ret
- ; input: al with byte
- ; output: void
- print_char:
- mov ah, 0x0E
- int 0x10
- ret
- ; input: al with byte
- ; output: replace if_space to nop command
- ; writing dx in operand_1
- ; zeroing dx
- handle_space:
- call print_char
- mov ptr cs:if_space, word 0x9090
- mov ptr cs:if_space + 2, word 0x9090
- ;mov ptr cs:if_space + 4, byte 0x90
- mov word ptr operand_1, dx
- xor dx, dx
- jmp read_input
- ; input: al with byte
- ; output: addition
- handle_enter:
- push ax
- mov al, 0x0A
- call print_char
- pop ax
- call print_char
- mov word ptr operand_2, dx
- jmp addition
- ;0110 1010 1001 0000
- ;0000 1001 1010 0110
- ; input: operand_1, operand_2 with word
- ; output: void
- addition:
- mov ax, word ptr operand_1
- mov dx, word ptr operand_2
- add dx, ax
- jc print_1
- end_print_1:
- rol dl, 4
- rol dh, 4
- mov al, dh
- mov ah, dl
- xor dx, dx
- mov bx, 0x10
- mov cx, 4
- print_sum:
- test cx, cx
- je exit
- dec cx
- xor dx, dx
- div bx
- cmp dl, 0xA
- jl print_dec
- jmp print_hex
- ; input: void
- ; output: al with 0x31
- print_1:
- mov al, 0x31
- call print_char
- jmp end_print_1
- ; input: dl with byte
- ; output: void
- print_dec:
- push ax
- mov al, dl
- add al, 0x30
- call print_char
- pop ax
- jmp print_sum
- ; input: dl with byte
- ; output: void
- print_hex:
- push ax
- mov al, dl
- add al, 0x37
- call print_char
- pop ax
- jmp print_sum
- exit:
- mov ax, 0x4C00
- int 21h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement