Member_2_8211500
asked on
Assignment for assembly language
I need help with my assembly language assignment. I'm not sure how to write three times a step to repeats. And how can I write code for
DisplayDiff: calculates and displays the difference. (first input - the second input)
Please, somebody, help me I feel frustrated. I need to submit this tomorrow but I want to finish it today. Can someone help me as soon as possible??!!
This is my assignment looks like Write a program that:
1. Clears the screen, locates the cursor near the middle of the screen.
2. Prompts the user for two signed integers.
3. Displays their sum and difference.
4. Repeats the same steps three times. Clears the screen after each loop iteration.
5. You might need to call the following procedures from irvine32 library:
· ClrScr
· WriteString
· WriteInt
· ReadInt
· Crlf
· ReadChar
· Gotoxy
The Gotoxy procedure locates the cursor at a given row and column in the console window. By default, the console window’s X-coordinate range is 0 to 79 and the Y-coordinate range is 0 to 24. When you call Gotoxy, pass the Y-coordinate (row) in DH and the X-coordinate (column) in DL. Sample call:
mov dh,10 ; row 10
mov dl,20 ; column 20
call Gotoxy; locate cursor
6. You need to create the following procedures:
Locate. It needs to be called before anything displays on the screen. Where it sets the cursor position. Input: this procedure prompts the user and saves the input.
DisplaySum: calculates and displays the sum.
DisplayDiff: calculates and displays the difference. (first input - the second input)
WaitForKey; It needs to be called at the end of each iteration. It displays "Press any key..." and waits for an input
This is the code so far I write
DisplayDiff: calculates and displays the difference. (first input - the second input)
Please, somebody, help me I feel frustrated. I need to submit this tomorrow but I want to finish it today. Can someone help me as soon as possible??!!
This is my assignment looks like Write a program that:
1. Clears the screen, locates the cursor near the middle of the screen.
2. Prompts the user for two signed integers.
3. Displays their sum and difference.
4. Repeats the same steps three times. Clears the screen after each loop iteration.
5. You might need to call the following procedures from irvine32 library:
· ClrScr
· WriteString
· WriteInt
· ReadInt
· Crlf
· ReadChar
· Gotoxy
The Gotoxy procedure locates the cursor at a given row and column in the console window. By default, the console window’s X-coordinate range is 0 to 79 and the Y-coordinate range is 0 to 24. When you call Gotoxy, pass the Y-coordinate (row) in DH and the X-coordinate (column) in DL. Sample call:
mov dh,10 ; row 10
mov dl,20 ; column 20
call Gotoxy; locate cursor
6. You need to create the following procedures:
Locate. It needs to be called before anything displays on the screen. Where it sets the cursor position. Input: this procedure prompts the user and saves the input.
DisplaySum: calculates and displays the sum.
DisplayDiff: calculates and displays the difference. (first input - the second input)
WaitForKey; It needs to be called at the end of each iteration. It displays "Press any key..." and waits for an input
This is the code so far I write
include Irvine32.inc
.data
prompt1 BYTE "Enter a 32-bit signed integer: ",0
prompt2 BYTE "The sum of the integers is: ",0
array DWORD IntegerCount DUP(?)
.code
main PROC
call Clrscr ;clears the screen
mov dh,10 ;row 10 Y-Coordinate range 0-24
mov dl,20 ;column 20 x-Coordiinate range 0-79
call Gotoxy ;locate cursor
mov esi,OFFSET array
mov ecx,IntegerCount
call PromptForIntegers
call ArraySum
call DisplaySum
exit
main ENDP
PromptForIntegers PROC
pushad ;save all registers
mov edx,OFFSET prompt1 ;address of the prompt
L1:
call WriteString ;display string
call ReadInt ;read integer into EAX
call Crlf ;go to next output line
mov [esi],eax ;store in array
add esi,4 ;next integer
loop L1
popad ;restore all registers
ret
PromptForIntegers ENDP
ArraySum PROC
push esi ;save ESI,ECX
push ecx
mov eax,0 ;set the sum to zero
L2:
add eax,[esi] ;add each integer to sum
add esi,4 ;point to next integer
loop L2 ;repeat for array size,in our case its for two integers
pop ecx ;restore ECX,ESI
pop esi
ret ;sum is in EAX
ArraySum ENDP
DisplaySum PROC
push edx
mov edx,OFFSET prompt2 ;display message
call WriteString
call WriteInt ;display EAX
call Crlf
pop edx
ret
DisplaySum ENDP
End main
L3: --> I'm not too sure about how the loop3 supposed to look like.
loop L3
pop ecx, ;restore ECX,ESI
pop esi
ret ;difference is in EAX
Difference ENDP
DisplayDiff
End main
wait for key;
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
For difference Why a Loop... for sum is makes some sense... difference is only two numbers.
DiffInt PROC
mov esi, offset array
mov eax, [esi]
sub eax, [esi+4]
ret
diffint ENDP
DisplayDiff PROC
mov edx, offset prompt3
call WriteStr
call DiffInt
call writeint
call crlf
ret
DisplayDiff ENDP
OR:
DisplayDiff PROC
call DiffInt
push eax
mov edx, offset prompt3
call WriteStr
pop eax
call writeint
call crlf
ret
DisplayDiff ENDP