![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 5
Rep Power: 0
![]() |
A little help please
Hey I am new to this forum and very new to this forum. I am currently taking a computer science introductory course and I am having a little bit of trouble. We are using all the basic commands of assembly (I think) like mov, inp, cpy, div a, mul a, add a, brz (branch if zero) a, brp a (branch if positive), jmp (jump), etc. I am trying to write a program that prints the ulam sequence....if that inputted number is even divide it by two...if its odd, multiply by three and add one....I am finding it very difficult to figure out how to test if the number is odd or even using these few commands, and using only 32 bytes. This is the only part I am stuck on....Could you please show me how to test if its even or odd using only the simple commands? Thank you very much for your time!
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4
![]() |
;number to check in eax
and eax, 1 jz label ; even ;else odd label:
__________________
-- lostcauz Stepped in what?... Behind whose barn?... I didn't even know they had a cow! |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
@lostcauz: Don't be comin' roun' giving simple answers when a complex one can be devised. We've talked about this....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Aug 2005
Location: England
Posts: 37
Rep Power: 0
![]() |
To be honest DaWei, Why not ? (I dont mean give the answer, that does`nt help anyone) but dangling incoherant fragments of information over somebody who is just trying to learn, is one of the reasons i dont post on this forum anymore!
I thought the purpose of a forum was to help people and share the knowledge, not make yourself feel omnipotent! |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
I reckon it is completely wasted on some people!
![]()
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Good lord, CodeJunkie! Lostcauz is a friend of mine; I'm yanking his chain! He will recognize that, even if you don't. Perhaps if you weren't looking for nonexistent issues to hype, the forum wouldn't seem so intolerable to you!
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Professional Programmer
|
lolz @ n00bs
![]() We all love each other, and whatnot.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4
![]() |
DaWei, I've slept since our last talk and as you know each day begins a new slate for me. Maybe brain damage or short-term memory loss. Hope I'm not in twubble...
![]() I almost gave the OP a link to this but I figured that would be 'overhelpin'. ![]()
__________________
-- lostcauz Stepped in what?... Behind whose barn?... I didn't even know they had a cow! |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
LOL, your solution was just so elegant I had to make a crack. I mean, one could arrange to do some shifts and work the carry flag in there, all sorts of high-powered looking stuff. I rarely mention elegance, but I keep my feelings about it in my signature. It sometimes lives automatically in the best solutions.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|