View Single Post
Old Feb 1st, 2005, 6:40 AM   #7
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
I simply looked at your C code and wrote it in assembler. I offered some other code by a more experienced assembler programmer for comparison also. While compiler output is a good way to learn and see a conversion the goal, for me at least, is to write tighter, faster code than the compiler. Either way it's awesome to see some others interested in learning the language. I commented the code I wrote.
; assumes eax contains 'a' variable and ecx contains 'b' variable

begin:  cmp eax, ecx   ; compare the 2 variables
        je  getout     ; if equal, we are done
        ja  higher     ; if a is greater than b jump to higher
        sub ecx, eax   ; otherwise a<b so subtract a from b
        jmp begin      ; loop until equal
higher: sub eax, ecx   ; subtract b from a
        jmp begin      ; loop
getout:                ; result returned in eax
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote