Question: I have an issue with my code and have been struggling to fix the error in it . Essentially I need to use MACROs to
I have an issue with my code and have been struggling to fix the error in it Essentially I need to use MACROs to recieve signed numbers, convert them from a string to integers, store them in an array, then print the array of numbers before then printing, the sum and the average of all the numbers. Most of it seems like it should work since I had it working with unsigned, but now it it throwing error A Instruction operands must be the same size. If there is a way to call the strings that align with the values outside of some of SumNums and for the avg that would be great too. Any step by step on my error would also be a fantastic help. As understanding MACROs and their implementation has been rather difficult. Code is snipped for reference.
INCLUDE Irvineinc
data
Hellousr BYTE "Hello and welcome to a lowlevel I procedure",
intro BYTE "Please enter signed decimal integers",
intro BYTE "Each number needs to be small enough to fit inside a b
intro BYTE "After they are entered IDIV will display the list offset
intro BYTE "Please enter a signed integer:
outofrangeerror BYTE "The number entered is not a signed intiger inside bits
averagenumstr BYTE "The average number is:
numsumstr BYTE "The sum of all the numbers entered is:
usrenteredstr BYTE "The numbers are:",
goodbye
EmGetString MACRO intro bufferInputSize, inputcounter
PUSHAD
mov ed intro
WriteString
mov edx, OFFSET bufferInputSize
mov ec bufferSize
ReadString
mov edx, OFFSET inputcounter
mov dword ptr eax ; Store number of bytes read
POPAD
ENDM
mDisplayString MACRO bufferInputSize
PUSHAD
mov ad bufferInputSize
WriteString
POPAD
ENDM
code
Emain PROC
introduction
PUSH OFFSET signedArray
PUSH OFFSET inputtotal
PUSH OFFSET inputcounter
readVal
crlf
PUSH OFFSET averagenumstr
PUSH OFFSET numsumstr
PUSH OFFSET signedArray
displaySumAvg
Numloopcheck:
mGetString intro bufferInputSize, inputcounter
xor ebx,
mov esi, OFFSET bufferInputSize ; Address of buffer
cld
converterStrInt:
lodsb
cmp al
validnum
cmp al
errToUsr
cmp al
errToUsr
sub al
imul ebx, ebx,
add ebx,
converterStrInt
validnum:
mov edi ebx ; Store number in array
add edi, ; Move to next element
Numloopcheck
readvalComplete
errToUsr:
mDisplayString OFFSET outofrangeerror
crlf
dec
Numloopcheck
readvalComplete:
ret
readVal ENDP
writeVal PROC
push ebp
mov ebp,
mov adi, ebp ; Address of List
lea esi, bufferInputSize ; Point to string buffer
mov ecx, ; Loop counter
outerloop:
push
mov eax, edi ; Load number from the array
mov ebx, ; Initialize divisor
xor edx, edx ; Clear high part
divide:
div ebx ; Divide eax by
add dl ; Convert remainder to ASCII
stosb ; Store digit in buffer
test eax, eax ; Check if quotient is zero
divide ; Repeat until all digits are processed
; Nullterminate and display
mov al
stosb
lea edx, bufferInputSize
mDisplayString
pop
add edi, ; Move to next number in List
outerloop
pop
ret
displaySumAvg PROC
push
mOV
mov esi, eb
xor ebx,
mov ecx,
SumNums:
mov eax, esi
add ebx,
add esi,
lloogSumNums
; Display sum
mov eax, abx ; Sum in eax
push offset numsumstr
push eax ; Pass sum
writeVal
; Display average
xor adx,
mov eax, ebx
mov ecx,
div acx ; Compute average
push offset averagenumstr
push eax ; Pass average
writeVal
pop
ret
displaySumAvg ENDP
Gfaremel PROC
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
