首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OAM程序集代码错误

OAM程序集代码错误
EN

Stack Overflow用户
提问于 2013-07-14 08:45:30
回答 1查看 184关注 0票数 0

我似乎不能在这个代码中计算定期工资。它只是简单地计算加班时数,而不是包括固定工资在内的全部工资。Here是指向OAMulator编译器的链接。

代码语言:javascript
复制
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

这里出了什么问题,我如何才能修复它?

EN

回答 1

Stack Overflow用户

发布于 2013-07-14 16:00:34

代码语言:javascript
复制
BRP RT   #if hours is more than 40, branch to overtime

如果工作时数超过40小时,此分支跳过计算固定薪资的代码。所以你现在做的事情是这样的:

代码语言:javascript
复制
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;

当你真正想要的东西可能是这样的时候:

代码语言:javascript
复制
regular_pay = 40 * pay_rate;
total_pay = regular_pay;
if (overtime_hours > 0) {
    total_pay = total_pay + overtime_hours * overtime_rate * pay_rate;
}     
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17635514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档