Sign in to follow this  
Followers 0
V9s

joke Programmer logic in everyday life

36 posts in this topic

int GroceryShopping() {
    return Buy("Milk", g_Eggs ? 2 : 6);
}

:shiftyninja:

1 person likes this

Share this post


Link to post
Share on other sites

local BuyMilk = 2
if Eggs == true then
BuyMilk = 6
end
print (BuyMilk)
[/CODE]

Share this post


Link to post
Share on other sites

ok, someone, quick! x86 assembly!

Share this post


Link to post
Share on other sites

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.

1 person likes this

Share this post


Link to post
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:

1 person likes this

Share this post


Link to post
Share on other sites

Yep -- posted back in June:

http://www.neowin.ne...g-a-programmer/

I just had to be a little smart alec :p

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

Share this post


Link to post
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) :)

1 person likes this

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

:D I like the ternary operator version as well:

int
get_milk()
{
	return ( shop_has_eggs() ) ? 6 : 1;
}

+1 that's how I'd write it :)

Share this post


Link to post
Share on other sites

lol

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.