0

I cannot seem to calculate regular pay in this code. It simply computes the rate of overtime hours not the complete pay including regular pay. Here is the link to the OAMulator compiler.

SET 40     #put the value 40 into the accumulator
STA 50    #store the value 40 in address 50  (I chose 50 arbitrarily)
SET 1.5    #put the value 1.5 into the accumulator
STA 51    #store the value 1.5 in address 51
LDA 0      #input the number of hours worked
STA 52    #store the number of hours worked in address 52
LDA 0      #input the payrate
STA 53    #store the payrate at address 53
LDA 52   #load the number of hours worked into the accumulator
SUB 50   #subtract the number 40 (stored in address 50)
STA 54   #store overtime hours at address 54 
BRP RT   #if hours is more than 40, branch to overtime
LDA 50   #load 40 into the accumulator
MLT 53  #multiply by the payrate.
STA 55  #store REGULAR PAY pay in address 55
RT, LDA 52   #load the number of hours worked
LDA 54  #overtime hours
MLT 51 #overtime rate 
MLT 53 #payrate 
ADD 55 #add the regular pay 
STA 56 #all of the pay
BR FINAL  #branch to where you are going to print the week's pay
STA 56  #store total pay including regular pay and overtime pay in address 56
FINAL,STA 0  #output final pay
HLT

What's wrong here, and how can I fix it?

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
user2548833
  • 383
  • 1
  • 4
  • 7
  • the program will not output the total pay when overtime hours are inputed. I cannot seem to figure out where the error is. – user2548833 Jul 14 '13 at 01:08

1 Answers1

0
BRP RT   #if hours is more than 40, branch to overtime

This branch skips past the code that calculates the regular pay if the number of worked hours exceeds 40. So what you're currently doing is something like this:

if (overtime_hours <= 0) {
    regular_pay = 40 * pay_rate;
}
// Here regular_pay might not have been calculated
total_pay = overtime_hours * overtime_rate * pay_rate + regular_pay;

When what you actually want probably is something like this:

regular_pay = 40 * pay_rate;
total_pay = regular_pay;
if (overtime_hours > 0) {
    total_pay = total_pay + overtime_hours * overtime_rate * pay_rate;
}     
Michael
  • 57,169
  • 9
  • 80
  • 125
  • @GitaarLAB: It's C, which I used as "pseudo" code to point out the logical flaw in the OP's code, and to suggest a more appropriate code flow. I'll leave it to the OP to do the actual assembly code changes. – Michael Jul 14 '13 at 14:47