# Does anyone know Little Man Computer?



## Hillian (Apr 12, 2004)

I'm having some problems. I'm trying to have three inputs and then trying to find the largest of them and output that number. So far I have(op code):

901
397
901
398
901
399


I believe there should be branching after this somehow but I'm not entirely sure. I dont really understand the concept of branching. Can anyone help me out?


----------



## TheOutcaste (Aug 8, 2007)

You need to compare the numbers, and branch or not branch based on the result.
The only way you have to compare is to subtract one number from another, then branch if it's positive. If it's positive, the number that was in the accumulator is the same or larger than the number in the mail box.
If it's not positive, the number in the mailbox is larger.
See if the flow chart here helps illustrate the concept:
http://www.atkinson.yorku.ca/~sychen/research/LMC/LMCDecisions.html


----------



## Hillian (Apr 12, 2004)

I got it finally after like 2 hours...now I have to modify it to output the numbers from largest to smallest...hmm...any help on that one? Heres what I have that works for the largest:


0 : 901
1 : 397
2 : 901
3 : 398
4 : 297
5 : 808
6 : 597
7 : 617
8 : 598
9 : 901
10 : 399 
11 : 298
12 : 824 
13 : 902
14 : 598
15 : 902
16 : 0
17 : 901 
18 : 399
19 : 297
20 : 822
21 : 597
22 : 902
23 : 000
24 : 599
25 : 902
97 : 000 DATA
98 : 000 DATA
99 : 000 DATA


----------



## TheOutcaste (Aug 8, 2007)

You'll need a Halt in line 26
Here's what I came up with for finding the largest, using 17 lines:
00 : 901
01 : 397
02 : 901
03 : 398
04 : 901
05 : 399
06 : 297
07 : 810
08 : 597
09 : 611
10 : 599
11 : 298
12 : 815
13 : 598
14 : 616
15 : 599
16 : 902
17 : 000
97 : 000 DATA
98 : 000 DATA
99 : 000 DATA

To output in sorted order, you'd need to do what is called a bubble sort
Compare two numbers (2 and 3).
If they are in the wrong order, set a flag and swap them
check the next number (1 and 2)
If they are in the wrong order, set a flag and swap them
If the flag is not set, we are done. If it is set, clear it, go back and check all the numbers again.
6 mail boxes for DATA, and 43 lines of code should do it.


----------

