In assembly language for x86 processors write a code that will log work hours and how much to
charge for each task along with calculating the stat avg.
While avoiding real numbers and the 32-bit binary they require store all hours data multiplied by
10, use dwords. Initialize the hours in an array and provide a corresponding array to be used to
hold the resulting amounts due; store the rate, multiplied by 100 (to get to pennies). While
computing the amounts due, adjust the result by dividing it by 10 (times were multiplied by 10
initially, which skews the amounts due), and compute the amounts due and total hours, use a
loop. Use the esi and edi registers to access array elements. Use only the eax, ebx, ecx, and edx
registers for processing, add the eax, ebx, ecx, and edx registers to the Watch, use the esi and edi
registers for the indices for the arrays, place breakpoints after calculating total hours, calculate
total due, calculate average hours, and calculate average due and on the ExitProcess. While
debugging, make sure all watches are viewable and add a memory view.
USE THESE VARIABLES: totTime (whole number * 10), totHours (whole), totMins (whole), totDue
(total in cents), totDueD (whole dollars), totDueC (whole), avgHours (in whole hours), avgMins (in
whole min), avgDueD (avg in dollars), avgDueC (avg in cents), and numCust (num customers set
by array examination).
USE PROCEDURES FOR THE FOLLOWING TASKS: Calculate Amounts Due, Calculate Total
Hours, calculate total minutes, Calculate Total Due (dollars & cents), Calculate Average Hours ,
calculate average minutes, and Calculate Average Due (dollars & cents).
HERE IS THE GIVEN CODE BELOW CORRECT IT SO IT RUNS WITHOUT ERRORS:
.386
.model flat,stdcall
.stack 4096
ExitProcess proto, dwExitCode:dword
.data
log_hours dd 80, 100, 60, 70, 90 ; hours worked on each task, multiplied by 10
log_rate dd 1200, 1500, 900, 1050, 1150 ; rate for each task, multiplied by 100
num_tasks equ 5 ; number of tasks in log_hours and log_rate arrays
.bss
totTime resd 1 ; total time worked, in tenths of an hour
totHours resd 1 ; total whole hours worked
totMins resd 1 ; total whole minutes worked
totDue resd 1 ; total amount due, in cents
totDueD resd 1 ; total amount due, in whole dollars
totDueC resd 1 ; total amount due, in cents
avgHours resd 1 ; avg hours worked
avgMins resd 1 ; avg min worked
avgDueD resd 1 ; avg amt due in whole dollars
avgDueC resd 1 ; avg amt due in cents
numCust resd 1 ; num of customers
.text
global _start
.code
main PROC
; PROCEDURES
; Calculate Amounts Due
; Parameters:
; esi: address of log_hours array
; edi: address of log_rate array
; ecx: number of tasks in log_hours and log_rate arrays
; Returns:
; eax: total amount due, in cents
calc_amounts_due:
xor eax, eax ; initialize total amount due to 0
calc_loop:
; Load hours and rate for current task
mov edx, [esi]
mov ebp, [edi]
; Multiply hours and rate
imul edx, ebp
; Add to total amount due
add eax, edx
; Move to next task
add esi,.
In assembly language for x86 processors write a code that wi.pdf
1. In assembly language for x86 processors write a code that will log work hours and how much to
charge for each task along with calculating the stat avg.
While avoiding real numbers and the 32-bit binary they require store all hours data multiplied by
10, use dwords. Initialize the hours in an array and provide a corresponding array to be used to
hold the resulting amounts due; store the rate, multiplied by 100 (to get to pennies). While
computing the amounts due, adjust the result by dividing it by 10 (times were multiplied by 10
initially, which skews the amounts due), and compute the amounts due and total hours, use a
loop. Use the esi and edi registers to access array elements. Use only the eax, ebx, ecx, and edx
registers for processing, add the eax, ebx, ecx, and edx registers to the Watch, use the esi and edi
registers for the indices for the arrays, place breakpoints after calculating total hours, calculate
total due, calculate average hours, and calculate average due and on the ExitProcess. While
debugging, make sure all watches are viewable and add a memory view.
USE THESE VARIABLES: totTime (whole number * 10), totHours (whole), totMins (whole), totDue
(total in cents), totDueD (whole dollars), totDueC (whole), avgHours (in whole hours), avgMins (in
whole min), avgDueD (avg in dollars), avgDueC (avg in cents), and numCust (num customers set
by array examination).
USE PROCEDURES FOR THE FOLLOWING TASKS: Calculate Amounts Due, Calculate Total
Hours, calculate total minutes, Calculate Total Due (dollars & cents), Calculate Average Hours ,
calculate average minutes, and Calculate Average Due (dollars & cents).
HERE IS THE GIVEN CODE BELOW CORRECT IT SO IT RUNS WITHOUT ERRORS:
.386
.model flat,stdcall
.stack 4096
ExitProcess proto, dwExitCode:dword
.data
log_hours dd 80, 100, 60, 70, 90 ; hours worked on each task, multiplied by 10
log_rate dd 1200, 1500, 900, 1050, 1150 ; rate for each task, multiplied by 100
num_tasks equ 5 ; number of tasks in log_hours and log_rate arrays
.bss
totTime resd 1 ; total time worked, in tenths of an hour
totHours resd 1 ; total whole hours worked
totMins resd 1 ; total whole minutes worked
totDue resd 1 ; total amount due, in cents
totDueD resd 1 ; total amount due, in whole dollars
totDueC resd 1 ; total amount due, in cents
avgHours resd 1 ; avg hours worked
avgMins resd 1 ; avg min worked
avgDueD resd 1 ; avg amt due in whole dollars
avgDueC resd 1 ; avg amt due in cents
numCust resd 1 ; num of customers
.text
global _start
2. .code
main PROC
; PROCEDURES
; Calculate Amounts Due
; Parameters:
; esi: address of log_hours array
; edi: address of log_rate array
; ecx: number of tasks in log_hours and log_rate arrays
; Returns:
; eax: total amount due, in cents
calc_amounts_due:
xor eax, eax ; initialize total amount due to 0
calc_loop:
; Load hours and rate for current task
mov edx, [esi]
mov ebp, [edi]
; Multiply hours and rate
imul edx, ebp
; Add to total amount due
add eax, edx
; Move to next task
add esi, 4
add edi, 4
loop calc_loop
ret
; Calculate Total Hours
; Parameters:
; esi: address of log_hours array
; ecx: number of tasks in log_hours array
; Returns:
; eax: total time worked, in tenths of an hour
; Clobbers:
; eax, ebx, ecx, edx
calc_total_hours:
xor eax, eax ; initialize total time worked to 0
calc_loop:
; Load hours for current task
mov edx, [esi]
; Add to total time worked
add eax, edx
; Move to next task
add esi, 4
3. loop calc_loop
ret
; Calculate Total Minutes
; Parameters:
; eax: total time worked, in tenths of an hour
; Returns:
; edx: total time worked, in whole minutes
; Clobbers:
; eax, edx
calc_total_minutes:
xor edx, edx ; initialize total minutes to 0
mov ebx, 6 ; 60 (minutes per hour) / 10 (multiplier for hours)
div ebx ; divide by 6 to get total minutes
ret
; Calculate Total Due
; Parameters:
; eax: total amount due, in cents
; Returns:
; totDueD: total amount due, in whole dollars
; totDueC: total amount due, in cents
; Clobbers:
; eax, ebx, edx
calc_total_due:
; Compute whole dollars and cents separately
xor ebx, ebx ; initialize total dollars to 0
mov ecx, 100 ; 100 cents per dollar
div ecx ; divide by 100 to get total dollars
mov [totDueD], eax
xor eax, eax
mov ecx, 100 ; 100 cents per dollar
div ecx ; remainder is total cents
mov [totDueC], eax
ret
; Calculate Average Hours
; Parameters:
; eax: total time worked, in tenths of an hour
; ecx: number of tasks
; Returns:
; avgHours: average time worked, in whole hours
; Clobbers:
; eax, ebx, ecx, edx
calc_avg_hours:
4. xor edx, edx ; initialize total whole hours to 0
mov ebx, 10 ; 10 (multiplier for hours)
div ebx ; divide by 10 to get total whole hours
mov [totHours], eax
xor eax, eax
mov eax, [totHours]
div ecx ; divide by number of tasks to get average whole hours
mov [avgHours], eax
ret
; Calculate Average Minutes
; Parameters:
; eax: total time worked, in tenths of an hour
; ecx: number of tasks
; Returns:
; avgMins: average time worked, in whole minutes
; Clobbers:
; eax, edx
calc_avg_minutes:
xor edx, edx ; initialize total whole minutes to 0
mov ebx, 6 ; 60 (minutes per hour) / 10 (multiplier for hours)
div ebx ; divide by 6 to get total whole minutes
mov [totMins], edx
xor eax, eax
mov eax, [totMins]
div ecx ; divide by number of tasks to get average whole minutes
mov [avgMins], eax
ret
; Calculate Average Due
; Parameters:
; eax: total amount due, in cents
; ecx: number of tasks
; Returns:
; avgDueD: average amount due, in whole dollars
; avgDueC: average amount due, in cents
; Clobbers:
; eax, ebx, ecx, edx
calc_avg_due:
; Compute whole dollars and cents separately
xor ebx, ebx ; initialize total dollars to 0
mov ecx, 100 ; 100 cents per dollar
div ecx ; divide by 100 to get total dollars
xor eax, eax ; save total dollars in eax
5. mov ebx, [totHours] ; use totHours as temporary storage for total whole hours
mov [totHours], edx ; save total cents in totHours
mov eax, ebx ; restore total whole hours
div ecx ; divide by number of tasks to get average whole dollars
mov [avgDueD], eax
xor eax, eax
mov eax, [totHours]
div ecx ; divide total cents by number of tasks to get average cents
mov [avgDueC], eax
ret
; MAIN PROGRAM
_start:
; Calculate total time worked
lea esi, [log_hours]
mov ecx, [num_tasks]
call calc_total_hours
mov [totTime], eax
; Calculate total minutes worked
call calc_total_minutes
; Calculate total amount due
lea esi, [log_hours]
lea edi, [log_rates]
call calc_total_due
; Calculate average time worked
call calc_avg_hours
call calc_avg_minutes
; Calculate average amount due
mov eax, [totDue]
call calc_avg_due
; Exit the program
push 0
call [ExitProcess]
; DATA SECTION
.data
log_hours dd 1, 2, 3, 4, 5 ; Array of hours worked, multiplied by 10
log_rates dd 150, 100, 125, 200, 175 ; Array of rates, multiplied by 100
num_tasks dd 5 ; Number of tasks in the arrays
totTime dd 0 ; Total time worked, in tenths of an hour
totHours dd 0 ; Total time worked, in whole hours
totMins dd 0 ; Total time worked, in whole minutes
totDue dd 0 ; Total amount due, in cents
totDueD dd 0 ; Total amount due, in whole dollars
6. totDueC dd 0 ; Total amount due, in cents
avgHours dd 0 ; Average time worked, in whole hours
avgMins dd 0 ; Average time worked, in whole minutes
avgDueD dd 0 ; Average amount due, in whole dollars
avgDueC dd 0 ; Average amount due, in cents
; IMPORT SECTION
.idata
invoke ExitProcess, 0
main endp
end main
HERE ARE THE ERRORS THAT APPEAR (CORRECT THEM SO IT WILL DEBUG CLEANLY
WITH NO ISSUES AND WORK AS INTENDED IN VISUAL STUDIOS: