enlightenedby42
Supreme [H]ardness
- Joined
- Jan 19, 2005
- Messages
- 4,412
This is making me crazy and I'm sure its something simple...
Taking an assembly class, using NASM. The assignment is to read a dat file that has some employee names, pay rates, and hours worked. Supposed to calculate pay with time and a half overtime if applicable. Have everything working, but it seems to be skipping through my "if-then" logic which applies the overtime if hrs>40. ie It just multiplies rate by hours no matter what. Anyone happen to know what I'm missing here? Jeezus this should NOT have been my third cs class. Quite a trial by fire. This has been making me crazy for like 8 hrs. now...Anyway...here's the code...it seems to be skipping past the section with the label "overtime"
Taking an assembly class, using NASM. The assignment is to read a dat file that has some employee names, pay rates, and hours worked. Supposed to calculate pay with time and a half overtime if applicable. Have everything working, but it seems to be skipping through my "if-then" logic which applies the overtime if hrs>40. ie It just multiplies rate by hours no matter what. Anyone happen to know what I'm missing here? Jeezus this should NOT have been my third cs class. Quite a trial by fire. This has been making me crazy for like 8 hrs. now...Anyway...here's the code...it seems to be skipping past the section with the label "overtime"
Code:
%include "asm_io.inc"
extern printf
extern fopen
extern fclose
extern fscanf
segment .data
dec_pt db ".",0
fmt2 db "%02d",0
ioutfmt db "%15d",0
fname db "pay.dat",0
mode db "r",0
handle dd 0
rate dd 0
hours dd 0
total dd 0
over dd 0
ifmt db "%s%d%d%d",0
ofmt db "%-15s%5d.%02d%7d%5d.%02d",0
blank db " ",0
x100 dd 100
h40 dd 40
ot2 dd 2
name db " ",0
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
mov eax,mode
push eax
mov eax,fname
push eax
call fopen
add esp,8
mov [handle],eax
top:
mov eax,total
push eax
mov eax,hours
push eax
mov eax,rate
push eax
mov eax,name
push eax
mov eax,ifmt
push eax
mov eax,[handle]
push eax
call fscanf
add esp,24
cmp eax,-1
je near done
mov eax,[hours]
cmp eax,[h40]
jl regular
overtime:
mov eax,[rate] ;move rate to eax
imul dword [h40] ;find pay for 40 hr
mov [total],eax ;move to total
mov eax,[hours] ;move hours to eax
sub eax,[h40] ;subtract 40 hours from total hours
mov [over],eax ;move overtime hours
mov eax,[rate] ;move pay rate to eax
cdq
idiv dword [ot2] ;divide pay by 2
add eax,[rate] ;add result to regular pay
imul dword [over]
add [total],eax
mov eax,[total]
cdq
idiv dword [x100]
mov ebx,eax
mov ecx,edx
regular:
mov eax,[rate]
imul dword [hours]
cdq
idiv dword [x100]
mov ebx,eax
mov ecx,edx
print:
mov eax,[rate]
cdq ; need to init edx!
idiv dword [x100]
push ecx
push ebx
push dword [hours]
push edx
push eax
push dword name
push dword ofmt
call printf
add esp,28
call print_nl
jmp top
done:
mov eax,[handle]
push eax
call fclose
add esp,4
popa
leave
mov eax,0
ret