• 100% Satisfaction Guarantee
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience:  Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
44076068
Ingo U is online now

1. Write a Little Man program to accept an indefinite number

Customer Question

1. Write a Little Man program to accept an indefinite number of input values. The output value will be the largest of the input values. You should use the value 0 as a flag to indicate the end of input.

2. Now write a Little Man program that accepts three values as input and outputs them in order of size, largest to smallest. (Use the code I already have for this and just modify it for a swapping)

3. Finally write a Little Man program that prints out the sums of the odd values from 1 to 39. The output will consist of 1, 1+3, 1+3+5, 1+3+5+7 . . . . No input is required. As an aside, do you notice anything interesting about the output results that are produced by this series? (Hint: This series is sometimes used as part of an algorithm for finding square roots of numbers.)
Submitted: 3 years ago.
Category: Homework
Expert:  Ingo U replied 3 years ago.
Hi,
could you please post or upload the code provided by the instructor that was mentioned?
Also, I have sent an underpriced report, since this is really 3 questions. Please consider raising the amount.
Regards,
Ingo U
Customer: replied 3 years ago.

the code that I already have to input 3 numbers by a user and then output the largest (no infinite number or flag) is:

INP
STA FIRST
INP
STA SECOND
INP
STA THIRD
LDA FIRST
SUB SECOND
BRP FGS
LDA SECOND
BRA NEXT
FGS LDA FIRST
NEXT STA BIGGERONE
SUB THIRD
BRP TNG
LDA THIRD
BRA RESULT
TNG LDA BIGGERONE
RESULT OUT
HLT
FIRST DAT
SECOND DAT
THIRD DAT
BIGGERONE DAT

Expert:  Ingo U replied 3 years ago.
Which simulator are you using? There are several out there... I should make sure I have the same environment.
Customer: replied 3 years ago.

http://www.atkinson.yorku.ca/~sychen/research/LMC/LittleMan.html

And yes the code that I responded with should be the main heart of it. Thank you!

Customer: replied 3 years ago.

What time do you think you can have this done by? I have to make print screens of it and type up the document for it as well. Please let me know the approximate time you expect to have this done by. Thank you!

Expert:  Ingo U replied 3 years ago.
A couple of hours I'd say...
Customer: replied 3 years ago.

2 hours will be pushing it, but I understand. Please try and get it done as soon as you can - I greatly appreciate your business and will give you excellent feedback if done by an hour and a half :) Thanks again!

Customer: replied 3 years ago.

and a bonus

Expert:  Ingo U replied 3 years ago.
Do you have a document describing the instruction set of this LMC? It looks a little different from ones I've used.
Customer: replied 3 years ago.

whatever way you can get it to work is fine - like if you need to put the 901 and the 399 and all that stuff. totally doesn't matter to me as this is due in less than 2 hours

FIGURE 6.3

Little Man Mnemonic Instruction Codes with

Their Corresponding OP Codes

LDA

STO

SUB

IN

OUT

COB or HLT

BRZ

BRP

BR

DAT

5xx

3xx

1xx

2xx

901

902

000

7xx

8xx

6xx

Store

Subtract

Input

Output

Coffee break (or Halt)

Branch if zero

Branch if positive or zero

Branch unconditional

Data storage location

(the first ‘‘m’’ is silent). Once you learn to read these mnemonics, you’ll find that programs

written with mnemonics are generally easy to read. It is more common to write programs this

way. For a while, we will continue to print both the mnemonic and the code, but eventually,

we will stop printing the code. Most programs are also written with comments, which help

to clarify the code. The mnemonic instructions that we will use are shown in Figure 6.3.

The

DAT abbreviation is used to indicate that a particular mailbox will be used to store data.

The data may be specified in advance, for example, to use as a constant, or it may be zero if

the particular location is to be used to store the data later, during execution of the program.

The program, shown in Figure 6.4, works as follows: the first four instructions simply

input and store the two numbers. The fifth instruction, in mailbox 04, subtracts the first

FIGURE 6.4

LMC Program to Find Positive Difference of Two

Numbers

00

01

02

03

04

05

06

07

08

09

10

11

IN

STO

IN

STO

SUB

BRP

LDA

SUB

OUT

COB

DAT

DAT

901

310

901

311

210

808

510

211

902

000

000

000

test

negative; reverse order

print result and

stop.

used for data

10

11

10

08

10

11

00

00

Expert:  Ingo U replied 3 years ago.
Here are the first 2:

So you can start working on your end...
Customer: replied 3 years ago.

Thank you for letting me work on that while you finish the last 1. Do you know how to make it look more like the code I sent you? It is pretty similar, but if you could make the code I sent you look the same as yours that would be good.

I just want all the codes to look the same format

Sorry that I am new on this site and don't really know how this works. Thanks!

Expert:  Ingo U replied 3 years ago.
Here's the 3rd one:

The interesting thing about the output it it's all squares from 1*1 through 20*20

In what way does my code not look like yours? Formatting? I used tabs to be able to read it better. But as far as the actual code, of course I had to write different instructions and use different labels. The main thing is that it works, isn't it? Which I believe all 3 do...
Customer: replied 3 years ago.

can you tab the code I gave you so it matches the same formatting? and also - should there be a number in the mailbox number 36 on this program:

INP
STA FIRST
INP STA SECOND
INP
STA THIRD
TOP LDA FIRST
SUB SECOND
BRP SWAPFS
LDA SECOND
SUB THIRD
BRP SWAPST
BRA RESULT
SWAPFS LDA FIRST
STA TMP LDA SECOND
STA FIRST
LDA TMP
STA SECOND
BRA TOP
SWAPST LDA SECOND
STA TMP
LDA THIRD
STA SECOND
LDA TMP
STA THIRD
BRA TOP
RESULT LDA FIRST
OUT
LDA SECOND
OUT
LDA THIRD
OUT
HLT
FIRST DAT
SECOND DAT
THIRD DAT
TMP DAT

Expert:  Ingo U replied 3 years ago.
Are you saying you'd like me to format the code you gave me to match my tab format? No problem. As you can see above, pasting tabbed code (from notepad, for example) gets messed up on this website. But in the text file, in notepad, things should line up nice and neatly.
When I load the program above, P2.txt, mailbox 36 corresponds to the number THIRD.
What the program does is sort the values FIRST, SECOND and THIRD in ascending order. In order to swap any two of them, we also need a temporary variable, TMP, in mailbox 37. In the end it'll still have whatever the last value that needed to be stored temporarily for swapping.
Expert:  Ingo U replied 3 years ago.

Customer: replied 3 years ago.

excellent, the last thing is - could you explain the 3rd program to me a little more clear. I don't see the pattern from the lmc