Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program for each problem and you should uploaded to simulator, then Subm

ID: 3802289 • Letter: W

Question

Write a program for each problem and you should uploaded to simulator, then Submit ( the simulator will translated LMC code to assembly language instruction ), then RUN to compile your program. Test your logic using the simulator on the provided link. Using the link for LMC papers and use the simulator (http://peterhigginson.co.uk/LMC/)

PLEASE provide the following:

1.          Complete LMC code for each problem.

2.          Print screen of the output results of each problem after you run the program.

3. for each problem submit the above two items in a word documents for each problem.

  

Question

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?(the series is sometimes used as part of an algorithm for finding square roots of numbers.)

Little Man Computer references

Numeric code

Mnemonic code

Instruction

Description

1xx

ADD

ADD

Add the value stored in mailbox xx to whatever value is currently on the accumulator (calculator).

Note: the contents of the mailbox are not changed, and the actions of the accumulator (calculator) are not defined for add instructions that cause sums larger than 3 digits.

2xx

SUB

SUBTRACT

Subtract the value stored in mailbox xx from whatever value is currently on the accumulator (calculator).

Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results - however, a negative flag will be set so that 8xx (BRP) can be used properly.

3xx

STA

STORE

Store the contents of the accumulator in mailbox xx (destructive).

Note: the contents of the accumulator (calculator) are not changed (non-destructive), but contents of mailbox are replaced regardless of what was in there (destructive)

5xx

LDA

LOAD

Load the value from mailbox xx (non-destructive) and enter it in the accumulator (destructive).

6xx

BRA

BRANCH(unconditional)

Set the program counter to the given address (value xx). That is, value xx will be the next instruction executed.

7xx

BRZ

BRANCH IF ZERO (conditional)

If the accumulator (calculator) contains the value 000, set the program counter to the value xx. Otherwise, do nothing.

Note: since the program is stored in memory, data and program instructions all have the same address/location format.

8xx

BRP

BRANCH IF POSITIVE (conditional)

If the accumulator (calculator) is 0 or positive, set the program counter to the value xx. Otherwise, do nothing.

Note: since the program is stored in memory, data and program instructions all have the same address/location format.

901

INP

INPUT

Go to the INBOX, fetch the value from the user, and put it in the accumulator (calculator)

Note: this will overwrite whatever value was in the accumulator (destructive)

902

OUT

OUTPUT

Copy the value from the accumulator (calculator) to the OUTBOX.

Note: the contents of the accumulator are not changed (non-destructive).

0

HLT

HALT

Stop working.

DAT

DATA

This is an assembler instruction which simply loads the value into the next available mailbox. DAT can also be used in conjunction with labels to declare variables. For example, DAT 984 will store the value 984 into a mailbox.

Numeric code

Mnemonic code

Instruction

Description

1xx

ADD

ADD

Add the value stored in mailbox xx to whatever value is currently on the accumulator (calculator).

Note: the contents of the mailbox are not changed, and the actions of the accumulator (calculator) are not defined for add instructions that cause sums larger than 3 digits.

2xx

SUB

SUBTRACT

Subtract the value stored in mailbox xx from whatever value is currently on the accumulator (calculator).

Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results - however, a negative flag will be set so that 8xx (BRP) can be used properly.

3xx

STA

STORE

Store the contents of the accumulator in mailbox xx (destructive).

Note: the contents of the accumulator (calculator) are not changed (non-destructive), but contents of mailbox are replaced regardless of what was in there (destructive)

5xx

LDA

LOAD

Load the value from mailbox xx (non-destructive) and enter it in the accumulator (destructive).

6xx

BRA

BRANCH(unconditional)

Set the program counter to the given address (value xx). That is, value xx will be the next instruction executed.

7xx

BRZ

BRANCH IF ZERO (conditional)

If the accumulator (calculator) contains the value 000, set the program counter to the value xx. Otherwise, do nothing.

Note: since the program is stored in memory, data and program instructions all have the same address/location format.

8xx

BRP

BRANCH IF POSITIVE (conditional)

If the accumulator (calculator) is 0 or positive, set the program counter to the value xx. Otherwise, do nothing.

Note: since the program is stored in memory, data and program instructions all have the same address/location format.

901

INP

INPUT

Go to the INBOX, fetch the value from the user, and put it in the accumulator (calculator)

Note: this will overwrite whatever value was in the accumulator (destructive)

902

OUT

OUTPUT

Copy the value from the accumulator (calculator) to the OUTBOX.

Note: the contents of the accumulator are not changed (non-destructive).

0

HLT

HALT

Stop working.

DAT

DATA

This is an assembler instruction which simply loads the value into the next available mailbox. DAT can also be used in conjunction with labels to declare variables. For example, DAT 984 will store the value 984 into a mailbox.

Explanation / Answer

I am attaching implementation in three different language i.e Java , C++, C :

Implementation of this question in Java :
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class as per your wish */
class LittleMan
{
public static void main (String[] args) throws java.lang.Exception
{
int i,sum=0;
for(i=1;i<=39;i+=2) {
sum += i;
System.out.print(sum + ", ");
}
}
}

Implementation of this question in C++ :
#include <iostream>
using namespace std;

int main() {
int i,sum=0;
for(i=1;i<=39;i+=2) {
sum += i;
cout<<sum<<", ";
}
return 0;
}

Implementation of this question C :
#include <stdio.h>

int main(void) {
int i,sum=0;
for(i=1;i<=39;i+=2) {
sum += i;
printf("%d, ",sum);
}
return 0;
}

OUTPUT : 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400,

output is same in all the three language implementation.

Inference : As we can see from the output that all the numbers printed are the square of 1,2,3 and so on up to 20 as the last output is 400

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote