Please help me with this program
Your assignment is to write an assembler program which does the following:
(1) prints your name and NYIT I.D. as a first action.
(2) reads in two 2-digit integers, one keystroke at a time, and operates Euclid’s algorithm on them
(3) prints the result – the HCF of the two
Notes:
Your program MUST be copiously commented.
The restrictions on inputs from the user to 1 through 99 means that you can use a byte to store each
number, as the worst case in 99, and this fits into a byte. But it is up to you.
Well, I've tried but i am not able to put two integers in a key stroke.. I can only put one digit integer i.e from 1 to 9
I need it from 1 to 99
and have to find the h.c.f value.
the program is as below
.model small
.stack 200h
.data
welcome db 'Name - Nisith Borad I.D. - 0569729 Using Euclids algorithm to find the HCF', 0Ah, 0Dh, 'of two positive integers between 1 and 99.', 0Ah, 0Dh, '$'
prompt2 db 0Ah, 0Dh, 'Please type the first integer $'
prompt3 db 0Ah, 0Dh, 'Please type the second integer $'
prompt4 db 0Ah, 0Dh, 'The HCF is $'
goodbye db 0AH, 0Dh, 'quitting now$'
.code
;first, set the pointer to the start of the data segment to provide access to the strings
mov dx, @data
mov ds, dx
;print opening prompt
mov dx, offset welcome ;set the offset to the 'welcome' string
mov ah, 9d ;BIOS code for print a dollar terminated string
int 21h ;invoke BIOS -- prints the string at DS::DX, always
;begin algorithm by reading in two 1-digit integers
;print the prompt first, using BIOS code '9d'
mov dx, offset prompt2
mov ah, 9d
int 21h
;now get the keystroke
mov ah, 1d ;BIOS code for read a keystroke
int 21h ;invoke BIOS, ASCII code will be in register 'al' after this command
;save the keystroke in register 'cl'
;after we get the integer value from the ASCII code
;by subtracting hex 30 from the ASCII code value
sub al, 30h
mov cl,al
;now read the second integer as above
;first print the prompt using BIOS code '1d'
mov dx, offset prompt3 ;set the offset for DS::DX
mov ah, 9d ;set BIOS code
int 21h ;invoke BIOS
mov ah, 1d ;BIOS code for read a keystroke
int 21h ;invoke BIOS, ASCII code will be in register 'al' after this command
sub ah, 30h
; we now have two integers, actual values not ASCII codes, one in 'cl' and the other in 'al'
repeat:
cmp cl, al ;compare the two integers
jz print_and_exit ;print the result and return control to operating system
;if here, the two numbers were **NOT** the same
;note that the flags are still set from the compare statement, but it's probably wise to do another
;one in case we change or edit the file.
cmp cl, al
jg greater ;test to see if cl > al, and if it is, jump to label 'greater'
;OK, so if we get to here, cl **must** be less than (<) al
sub al, cl ;diminish 'al' by 'cl'
jmp repeat ;go round the loop until the variables become equal
greater:
;if we get here, it was shown that cl > al, so diminish 'cl'
sub cl, al
jmp repeat ;go round the loop until the variables become equal
print_and_exit:
;there's only one way to get here and that's when the integers are equal
;so print and then we're done.
;first the prompt
mov dx, offset prompt4
mov ah, 9d ;BIOS code for print a string
int 21h
;last, the actual result
mov ah, 2d ;BIOS code for print to screen
;character's ASCII code must be in 'dl' for this to work
mov dl, cl ;starting to print 'cl's value
add dl, 30h ;convert value to ASCII code
int 21h
mov dx, offset goodbye
mov ah, 9d
int 21h
mov ah, 4ch ;BIOS code for exit/quit
int 21h
end