119k views
3 votes
1. Write an LMC (Little Man Computer) program to do the following task. if (value == 0) { some_statements; } next_statement;

2. Write an LMC program to add three numbers. The numbers are provided in the in-basket. The sum of the numbers should appear in the out-basket.

User Oscarz
by
3.1k points

1 Answer

3 votes

Answer:

The program is given below with appropriate comments for better understanding

Step-by-step explanation:

1) LMC Program:

LDA A //Load A

SUB B //Subtract from A, B which is 0.

SKZ // skip next statement if A-B == 0 , which is A == 0 as B is zero.

JMP ENDIF // jump to ENDIF point if A not equal to 0, else this step is skipped.

OUT // some statement , not called if A != 0.

ENDIF LDA A // jump statement arrives here if A != 0.

HLT //HALT

2) LMC Program:

//input first number

INP

//store it at address 99

STA 99

//input second number

INP

//add it to value at 99

ADD 99

//store the resulting sum to 99

STA 99

//input third number

INP

//add the number to value at 99 address(which is the sum of first and second number)

ADD 99

//output sum

OUT

//halt

HLT

User Alexandre Catalano
by
2.8k points