Programmer logic in everyday life


Recommended Posts

ok, someone, quick! x86 assembly!


proc BuyMilk

cmp 0, dwEggCount
jz @F ;ZF set? Jump [b]f[/b]orward
mov eax, 6 ;Has eggs, buy 6 milk.
ret

@@:
mov eax, 2 ;Has zero eggs, buy 2 milk
ret

BuyMilk endp
[/CODE]

I haven't played with assembly in a few years, but I guess that code would do if dwEggCount exists. :p

Just make sure that the amount of eggs is stored in dwEggCount and call BuyMilk to return how much milk that should be bought.

I used MASM when I played with it. A few modifications are needed to make it work for others.

I love @@-labels.

Link to comment
Share on other sites

title groc
.model small
.stack 100h

.data
eggs dw baadh
milk dw f00dh
bag dw d00dh

.code
.486

start:
mov ax, [eggs]
cmp ax, 0
jz noeggs
mov cx, 6
jmp initbuy
noeggs:
mov cx, 2

initbuy:
xor ax, ax
buy:
add ax, 1
mov edx, [milk + ax * 4]
mov [bag + ax * 4], edx
cmp ax, cx
jne buy
endbuy:

mov ax, 4c00h
int 21h
end start

And, before anyone points out, yes. I don't know shhh about x86 assembly (contrary to, for example, the post above), but, arguably, it still looks cool and I had to pretend I'm smart :geek:

Link to comment
Share on other sites

Threads merged

Thanks. I kind of figured it, but maybe I didn't search hard enough.

It's hard to find such a topic when it doesn't have an obvious title (like your one did, which is why I kept this title in the merged thread) :)

Link to comment
Share on other sites

Threads merged

It's hard to find such a topic when it doesn't have an obvious title (like your one did, which is why I kept this title in the merged thread) :)

Thanks, Calum.

Link to comment
Share on other sites

This topic is now closed to further replies.