Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 100h
- NL_ equ $d, $a ;new line
- mov ah, $9
- mov dx, helloStr_
- int 21h
- mov dx, inputA_
- int 21h
- mov ah, $a ;input to buff
- mov dx, buffNum
- int 21h
- add dx, 2 ;dx to the first char of number
- call str_to_int_ ;input dx - string that ends on 0dh, output al - 8 bit number
- mov bh, al ;save first number to bh
- mov ah, $2 ;output - new line
- mov dx, $0d0a
- int 21h
- mov ah, $9 ;output - inputStr
- mov dx, inputB_
- int 21h
- mov ah, $a ;input to buff
- mov dx, buffNum
- int 21h
- add dx, 2 ;get second number
- call str_to_int_
- mov dl, al ;save second to dl
- mov dh, bh ;move first to dh
- call task_ ;input dh - A, dl - B, output ax - 16 bit number
- mov dx, buffAns
- call int_to_str_ ;input ax - 16 bit number, dx - 6 byte buffer; output - string
- ;representation of number in buff that ends with $
- mov ah, $9 ;output - resultStr
- mov dx, resultStr_
- int 21h
- mov dx, buffAns ;output - buffAns
- int 21h
- mov dx, byeStr_ ;output - byeStr
- int 21h
- mov ah, $8 ;wait for input
- int 21h
- ret
- str_to_int_: ;input dx - string that ends on 0dh; output al - 8bit number
- push bp ;stack...
- mov bp, sp
- sub sp, 1 ;one byte for const
- mov byte [bp-1], 10 ;const 10
- push bx ;save
- mov bx, dx ;memory accessible only from bx
- xor ax, ax ;clear ax
- next_digit_:
- mul byte [bp-1] ;multiplied by 1 byte; result ah:al
- add al, [bx] ;add symbol to al
- sub al, '0' ;convert SYMBOL to NUMBER 0-9
- inc bx ;move to next symbol
- cmp byte [bx], $d ;are we at the last symbol?
- jne next_digit_ ;if no then there're still numbers to convert left
- pop bx ;retrieve
- mov sp, bp ;stack...
- pop bp
- ret ;go back
- int_to_str_: ;input ax - 16 bit number, dx - buffer (string with length of 6); output - string representation of number in buff that ends with $
- push ax ;save ...
- push dx
- push bx
- push bp ;stack...
- mov bp, sp
- sub sp, 2 ;reserve 2 bytes
- mov word [bp-2], 10 ;const 10 2 byte
- mov bx, dx ;address of buff to bx
- xor dx, dx ;clear dx
- push '*' ;"stopper" for string conversation
- push '$' ;last symbol
- next_letter_:
- div word [bp-2] ;divide dx:ax by 16bit number; result dx-remainder, ax-quotient
- add dx, '0' ;convert to ascii number
- push dx ;save symbol to stack
- xor dx, dx ;clear dx
- cmp ax, 0 ;have we converted whole number?
- jne next_letter_ ;if no there're still number to convert
- next_save_letter_:
- pop dx ;get symbol
- cmp dx, '*' ;is stopper?
- je exit_int_to_str_ ;if yes - exit
- mov [bx], dl ;if no move to buffer
- inc bx ;go to next symbol address
- jmp next_save_letter_ ;next letter
- exit_int_to_str_:
- mov sp, bp ;return stack pointer to its original state
- pop bp ;retrieve
- pop bx
- pop dx
- pop ax
- ret ;go back
- task_: ;input
- ;dh - A
- ;dl - B
- ;output ax
- xor ax, ax ;clear ax
- mov al, dh ;A to al
- mul al ; *A
- xor bh, bh
- mov bl, dl
- xor dx, dx
- div bx ; /B, mod in dx
- add ax, bx ; + B
- ret ;go back
- helloStr_ db "This program calculates the result of a*a/b+b", NL_, "Using register type procedure", NL_, "$"
- inputA_ db "Input number in range from 0 to 255:", NL_, "$"
- inputB_ db "Input number in range from 1 to 255:", NL_, "$"
- resultStr_ db NL_, "Result:", NL_, "$"
- byeStr_ db NL_, "Press anything to terminate a program...$"
- buffNum db 6, 0, 6 dup(?)
- buffAns db 6 dup (?)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement