Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3_1:
- org 100h
- NL_ equ 0dh, 0ah ;const
- mov ah, 09h ;output - helloStr
- mov dx, helloStr_
- int 21h
- mov dx, inputStr_ ;output - inputStr
- int 21h
- mov ah, 0ah ;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, 02h ;output - new line
- mov dx, 0d0ah
- int 21h
- mov ah, 09h ;output - inputStr
- mov dx, inputStr_
- int 21h
- mov ah, 0ah ;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:dl - two numbers, 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, 09h ;output - resultStr
- mov dx, resultStr_
- int 21h
- mov dx, buffAns ;output - buffAns
- int 21h
- mov dx, byeStr_ ;output - byeStr
- int 21h
- mov ah, 08h ;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], 0dh ;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 - 6 byte buffer; 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:dl - two numbers, output ax - 16 bit number
- xor ax, ax ;clear ax
- mov al, dl ;first number...
- mul dh ;...multiplied by second, 8bit*8bit=16bit => result in ax
- shl ax, 1 ;multiply by 2
- sub ax, 3 ;subtract 3
- ret ;go back
- helloStr_ db "This program calculates the result of 2*x*y-3", NL_, "Using register type procedure", NL_, "$"
- inputStr_ db "Input number in range from 0 to 254:", NL_, "$"
- resultStr_ db NL_, "Result:", NL_, "$"
- byeStr_ db NL_, "The program has now terminated. Press anything to continue...$"
- buffNum db 4, 0, 4 dup(?)
- buffAns db 6 dup (?)
- 3_2:
- org 100h
- NL_ equ 0dh, 0ah ;const
- mov ah, 09h ;output - helloStr
- mov dx, helloStr_
- int 21h
- mov dx, inputStr_ ;output - inputStr
- int 21h
- mov ah, 0ah ;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 [num1_], al ;mov first number to num1_
- mov ah, 02h ;output - new line
- mov dx, 0d0ah
- int 21h
- mov ah, 09h ;output - inputStr
- mov dx, inputStr_
- int 21h
- mov ah, 0ah ;input to buff
- mov dx, buffNum
- int 21h
- add dx, 2 ;get second number
- call str_to_int_
- mov [num2_], al ;move second number to num2_
- call task_ ;input num1_ & num2_ - two numbers, output numAns_ - 16 bit number
- mov ax, [numAns_]
- 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, 09h ;output - resultStr
- mov dx, resultStr_
- int 21h
- mov dx, buffAns ;output - buffAns
- int 21h
- mov dx, byeStr_ ;output - byeStr
- int 21h
- mov ah, 08h ;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], 0dh ;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 - 6 byte buffer; 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:dl - two numbers, output ax - 16 bit number
- push ax ;save
- mov al, [num1_] ;num1_ to al...
- mul [num2_] ;...multiplied by second, 8bit*8bit=16bit => result in ax
- shl ax, 1 ;multiply by 2
- sub ax, 3 ;subtract 3
- mov [numAns_], ax ;move answer to numAns_
- pop ax ;retrieve
- ret ;go back
- helloStr_ db "This program calculates the result of 2*x*y-3", NL_, "Using global var type procedure", NL_, "$"
- inputStr_ db "Input number in range from 0 to 254:", NL_, "$"
- resultStr_ db NL_, "Result:", NL_, "$"
- byeStr_ db NL_, "The program has now terminated. Press anything to continue...$"
- buffNum db 4, 0, 4 dup(?)
- num1_ db 0
- num2_ db 0
- numAns_ dw 0
- buffAns db 6 dup (?)
- 3_3:
- org 100h
- NL_ equ 0dh, 0ah ;const
- mov ah, 09h ;output - helloStr
- mov dx, helloStr_
- int 21h
- mov dx, inputStr_ ;output - inputStr
- int 21h
- mov ah, 0ah ;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
- xor ah, ah ;clear ah
- push ax ;save first number to stack
- mov ah, 02h ;output - new line
- mov dx, 0d0ah
- int 21h
- mov ah, 09h ;output - inputStr
- mov dx, inputStr_
- int 21h
- mov ah, 0ah ;input to buff
- mov dx, buffNum
- int 21h
- add dx, 2 ;get second number
- call str_to_int_
- xor ah, ah ;save second number to stack
- push ax
- call task_ ;input stack - two numbers, 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, 09h ;output - resultStr
- mov dx, resultStr_
- int 21h
- mov dx, buffAns ;output - buffAns
- int 21h
- mov dx, byeStr_ ;output - byeStr
- int 21h
- mov ah, 08h ;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], 0dh ;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 - 6 byte buffer; 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 stack - two numbers, output ax - 16 bit number
- push bp ;save...
- mov bp, sp ;move bp to sp
- push dx
- mov ax, [bp+4] ;first number
- mov dx, [bp+6] ;second number
- mul dl ;first multiplied by second, 8bit*8bit=16bit => result in ax
- shl ax, 1 ;multiply by 2
- sub ax, 3 ;subtract 3
- pop dx ;retrieve
- pop bp
- ret 4 ;go back clearing stack from 4byte of parameters
- helloStr_ db "This program calculates the result of 2*x*y-3", NL_, "Using stack type procedure", NL_, "$"
- inputStr_ db "Input number in range from 0 to 254:", NL_, "$"
- resultStr_ db NL_, "Result:", NL_, "$"
- byeStr_ db NL_, "The program has now terminated. Press anything to continue...$"
- buffNum db 4, 0, 4 dup(?)
- buffAns db 6 dup (?)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement