Write a LMC program that takes two inputs, a number to count down from, and the step value (example: count down from 35 by 5), until it reaches zero. It should print each step, and the last number before zero if the sequence doesn’t end on zero, but if the number goes to negative, that number should not be printed. Example output using 13 and 3 as inputs would be: 13, 10, 7, 4, 1. Example output using 12 and 3 as inputs would be: 12, 9, 6, 3, 0.

Write the code to calculate the area and perimeter of a triangle. The program should take 3 inputs, which are, in order, the base, height, and the third side of the triangle. The code should produce 2 values in the output box, the first number will be the area and the second, the perimeter. (Hint: you’ll probably want to use DAT statements to store some values to start).

Example code:

Calculate perimeter & area - takes L & W as inputs prints out perimeter first, then area. 00 LDA #01; 01 STA 99; 02 IN; 03 STA 98; 04 LDA #00; 05 STA 96; 06 IN; 07 STA 97; 08 ADD 97; 09 ADD 98; 10 ADD 98; 11 OUT; 12 LDA 96; 13 ADD 98; 14 STA 96; 15 LDA 97; 16 SUB 99; 17 STA 97; 18 SKZ; 19 JMP 12; 20 LDA 96; 21 OUT; 22 HLT;

MULTIPLIES TWO NUMBERS. 00 IN; 01 STA 99; 02 STA 97; 03 IN; 04 STA 98; 05 SUB 90; 06 STA 98; 07 SKZ; 08 JMP 12; 09 LDA 97; 10 OUT; 11 HLT; 12 LDA 97; 13 ADD 99; 14 STA 97; 15 LDA 98; 16 JMP 05; 90 DAT 001;

ADDS THE FIRST NUMBER INPUT TO ITSELF, THEN SUBTRACTS THE SECOND INPUT FROM THE TOTAL 00 IN; 01 STA 90; 02 IN; 03 STA 91; 04 LDA 90; 05 ADD 90; 06 SUB 91; 07 OUT; 08 HLT;

ONE WAY OF COUNTING FROM AN INPUT DOWN TO ZERO 00 IN; 01 OUT; 02 SUB 98; 03 SKP; 04 JMP 06; 05 JMP 01; 06 HLT; 98 DAT 002;

Hello, I'm a moderator for this topic. I've been working hard to find a professional to assist you right away, but sometimes finding the right professional can take a little longer than expected.

I wonder whether you're ok with continuing to wait for an answer. Please let me know and I will assist further. Thank you!

Hi, for the 2nd part, it didn't state that it's a right triangle. In that case, according to my knowledge of geometry, finding the 3rd side (in order to compute perimeter) involves finding a square root, or trig functions. It seems to me that would be excessively complicated. given the nature of the assignment and limited instruction set of LMC. Could it be that we can assume a right triangle, so the height is the third side? Thanks, Ingo U

Yes, it can be a right triangle or any type of triangle. I believe right would be the easiest to compute?

Customer:replied 3 years ago.

Ironically I just checked my e-mail and he added this to the instruction set:

For the triangle problem, you should assume a right triangle. The formula for area is 1/2 * b * h, and the perimeter is b + h + 3rd side. I apologize for any confusion in my wording about "you can assume any triangle". Any triangle has the same formula for area and perimeter, but if it's not a right triangle, there's an extra step you'd need to find the height.

For the test data, I'll be using 6 for base, 8 for height, and 10 for the hypotenuse. The perimeter is 24, and the area is the same.

One last note, I am grading based on whether the code returns the right results, not on efficiency. But, for efficiency, although both 1/2*(b*h) and (1/2*b)*h yield the same answer, the second is much more efficient, especially for something like little man.