# LMC Little man Computer Programing help?

ok, i know this sounds simple but ive been stuck for the past 3 days trying to figure this out can someone please help me with this i need to do the following,

1) Obtain 3 numbers
2) Determine which number is the smallest of the 3 numbers
3)Out put the smalles number and then halt.

this is what im trying to figure out in the Little man computer program anyone know the code to complete this and if you can kindly explain to me how you came up with that code that would be a life saver! thanks so much!!

Related Engineering and Comp Sci Homework Help News on Phys.org
phinds
Gold Member
2019 Award
you need to show some attempt yourself so we'll have some idea of your level of knowledge and where you are stuck.

Asking people here to just spoon-feed you a total answer is not how this forum works.

oh ok, yea im new to this fourm but this is what i have so far and its not really working

MB Op-Code Description
00 901 Input A
01 397 Store A in MB 97
02 901 Input B
03 398 Store B in MB 98
04 297 Subtract A from B
05 808 If positive, go to MB 08
06 598 Load MB 98 (B)
07 616 Send to MB 16
08 597 Load MB 97 (A)
09 901 Input C
10 399 Store C in MB 99
11 297 Subtract A from C
12 821 If positive, go to MB 21
14 902 Output MB 99 (C)
15 000 HALT
16 901 Input the data received from MB 07 (B)
17 398 Store B in MB 98
18 299 Subtract B from C
19 821 If positive, go to MB 21
20 599 Load MB 99 (C)
21 902 Output
22 000 HALT
24 902 Output
25 000 HALT
97 000 DATA
98 000 DATA
99 000 DATA

Mark44
Mentor
oh ok, yea im new to this fourm but this is what i have so far and its not really working

MB Op-Code Description
00 901 Input A
01 397 Store A in MB 97
02 901 Input B
03 398 Store B in MB 98
04 297 Subtract A from B
05 808 If positive, go to MB 08
06 598 Load MB 98 (B)
07 616 Send to MB 16
08 597 Load MB 97 (A)
09 901 Input C
10 399 Store C in MB 99
11 297 Subtract A from C
12 821 If positive, go to MB 21
14 902 Output MB 99 (C)
15 000 HALT
16 901 Input the data received from MB 07 (B)
17 398 Store B in MB 98
18 299 Subtract B from C
19 821 If positive, go to MB 21
20 599 Load MB 99 (C)
21 902 Output
22 000 HALT
24 902 Output
25 000 HALT
97 000 DATA
98 000 DATA
99 000 DATA
What does "not really working" mean? Please provide more detailed information - what works, what doesn't work, and so on.

ok, well im able to get the three numbers, and i subtract the first two and get an output, i was having my professor try and explain it to me, but it seems like he didn't even know what he was doing, so im stuck at figuring out a code or method that will determine the smallest of the three numbers any suggestion on determining that would be a great benefit to myself.

Mark44
Mentor
Here is one possible algorithm.
Code:
Input A and store it.
Input B and store it.
Input C and store it.

Compare A and B (by subtraction)
If A <= B
{
compare A and C
If A <= C
{
Store A (A is the smallest)
}
Else
{
Store C (C is the smallest)
}
Else
{
compare B and C
If B <= C
{
Store B (B is the smallest}
}
Else Store C (C is the smallest)
}
By "store X" I mean copy the value to some memory location that will hold the smallest value, similar to what you're doing for A, B, and C.

Hope that helps.