You are going to write a program that calculates the average of four integers. The resultant average will be an integer itself and should be printed (along with the four integers) in decimal format.
The integers should each appear in a SDWORD
directive
along with the initial value (which is used in calculating the average).
Don't forget to allocate storage for the average using the
SDWORD
directive (there is no initial value).
TITLE New Program - A sample of how to divide in assembler INCLUDE IRVINE32.inc .data DividendMsg BYTE "The dividend is ", 0 DivisorMsg BYTE "The divisor is ", 0 QuotientMsg BYTE "The quotient is", 0 RemMsg BYTE "The remainder is ", 0 Dividend SDWORD 37 ; The number that we divide INTO Divisor SDWORD 5 ; The number that we divide BY Quotient SDWORD ? ; The result Remainder SDWORD ? ; The remainder .code main proc mov edx, OFFSET DividendMsg ; Load the message's offset into edx call WriteString ; Print the message mov eax, Dividend ; Load the dividend into EAX call WriteInt ; Print the dividend call CrLf ; Go to the next line mov edx, OFFSET DivisorMsg ; Load the message's offset into edx call WriteString ; Print the message mov eax, Divisor ; Load the Divisor into EAX call WriteInt ; Print the Divisor call CrLf ; Go to the next line mov eax, Dividend ;Save the dividend cdq ; Convert it to a quad word with ; the upper double word in EDX idiv Divisor ; Divide it by Divisor mov Quotient, eax ; Save the quotient - it was in the EAX mov Remainder, edx ; Save the Remainder - it was in the EDX mov edx, OFFSET QuotientMsg ; Load the message's offset into EDX call WriteString ; Print the message call WriteInt ; Print the quotient call CrLf ; Go to the next line mov eax, Remainder ; Load the remainder so you can print it mov edx, OFFSET RemMsg ; Load the message's offset into EDX call WriteString ; Print the message call WriteInt ; Print the remainder call CrLf ; Go to the next line exit ; End the program main endp end main