Since the result register (EAX
EAX
) is 32-bit, should I take into account a possible result that may not fit in 32 bits? If I get a larger result, it won't display properly, and the user may be unaware.
Is doing a bunch of adds still faster than using mul
mul
?
http://www2.math.uni-wuppertal.de/~fpf/Uebungen/GdR-SS02/opcode_i.htmlThis suggests that on a Pentium, ADDADD
is about 3 cycles whereas MULMUL
is about 10 cycles. So MULMUL
is faster if you need to multiply by more than about 3 or 4.
I'm also avoiding mul
mul
because getting the bits in the right place for it is complicated, and I still cannot seem to get it right.
Perhaps ask about this on StackOverflowStack Overflow.
- Programmers who use high-level-languages are used to them; a nest of jump are "spaghetti code" and "goto is considered harmful" (compared with 'structured programming')
- A subroutine can be called from more than one place (i.e. reused)
- One of the problems with assembly is knowing what registers are used. You documented which registers are used by your code fragments. For larger programs you might want to define a standard used by all subroutine, for example, "any subroutine may use/corrupt eax
eax
through edx;edx
; if it alters any other register (e.g. esiesi
, ebpebp
, etc.) then it must save previous value before changing it and retorerestore old value after changing it before returning.
; assume the following calling cnventionsconventions:
; esi is the input parameter
; eax is the output value
; carry flag is set if there's an error
mov esi, input_lbl
call PutStr
call GetUint
jnc input_ok
mov esi, input_error
call PutStr
.EXIT
input_ok:
mov esi, eax
call factorial
jnc output_ok
mov esi, factorial_overflow_error
call PutStr
.EXIT
output_ok
push eax ; preserve the factorial value
mov esi, factorial_overflow_is
call PutStr
pop esi ; restore the factorial value
call PutUint
.EXIT
If GetLIntGetLInt
is a macro would it work to just say GetLInt EAX
?