LMC Little man Computer Programing help?

  • Thread starter Thread starter Freshman
  • Start date Start date
  • Tags Tags
    Computer
AI Thread Summary
The discussion revolves around programming a solution in Little Man Computer (LMC) to find the smallest of three input numbers. The user is struggling with their current code, which successfully inputs the numbers but fails to correctly determine the smallest. A suggested algorithm outlines a step-by-step comparison of the three numbers, storing the smallest value in memory. The importance of providing more details about what specifically isn't working in the code is emphasized for better assistance. The thread highlights the need for a clear understanding of LMC operations and logical comparisons to achieve the desired outcome.
Freshman
Messages
3
Reaction score
0
ok, i know this sounds simple but I've 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 I am 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!
 
Physics news on Phys.org
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 I am 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
13 599 Load MB 99
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
23 598 Load MB 98
24 902 Output
25 000 HALT
97 000 DATA
98 000 DATA
99 000 DATA
 
Freshman said:
oh ok, yea I am 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
13 599 Load MB 99
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
23 598 Load MB 98
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 I am 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 I am 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.
 
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.
 
Back
Top