Question: Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the
Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month, validate that it is between 1 and 31, and then display a table showing how much the salary was for each day worked, as well as the total pay earned for the month. The output should be displayed in pennies points, not in pennies
pls show input and output
This must be in 80x86 essembly language.
What I am having a challenge with is to convert the final answer from pennies to percent of a dollar. Example, 1 penny equals $0.01 dollars. I have most of the script, i just need to know how to convert to percentages.
Thanks in advance for the help!
; Calculate pennies earned by number of days between 1 and 31
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
prompt BYTE "Enter days worked from 1 to 31 :", 0
string DWORD 40 DUP (?)
sum DWORD 0
days DWORD 1
shift DWORD 1
resultLbl1 BYTE "Pennies earned = ", 0
resultLbl2 BYTE "The days entered are above 31", 0
sumString BYTE 11 DUP (?), 0
.CODE
_MainProc PROC
days_worked:
input prompt, string, 40 ; prompt for days worked
atod string ; convert
mov days, eax
mov ch, al ; set count loop value
mov CL, 0 ; set shift left value 2^n
cmp days,31 ; ck if over 31 days entered
ja days_worked ; if over 31 loop and prompt for days
pennies_day:
mov eax, 1 ; move 1 into eax for 2^n
shl eax, CL ; 2^n
add sum, eax ; results to sum
inc CL
;dec sum
dtoa sumString, sum ; convert sum to ASCII characters
output resultLbl1, sumString ; output the sum to the console
dec ch ; decrease loop counter by 1
cmp ch, 0 ; ck if counter = 0
je done ; if counter = 0 jump to done
jmp pennies_day ; else loop back
done:
;dtoa sumString, sum ; convert sum to ASCII characters
;output resultLbl1, sumString ; output the sum to the console
ret
_MainProc ENDP
END
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
