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

this is for logic system design class Use the PennSim simulator and assembler Th

ID: 3607227 • Letter: T

Question

this is for logic system design class

Use the PennSim simulator and assembler

This LC-3 assembly language program will interpret keystrokes as commands for printing characters on the console, resulting in “ASCII art” -- the ability to draw pictures using ASCII characters.

A command is one of the following:

a)A number followed by a character, which means to print that number of copies of the character. (E.g., 9* means to print *********.)

b)A linefeed (which is “Enter” or “Return” on your keyboard, which means to print a linefeed, moving to the beginning of the next line.

c)Any other character, which means to exit the program.

For example, if the user types the following, where ‘’ is used to represent Enter (linefeed):

3*3 3*
1 3*1 3*
2 5*
3 3*
4 1*
X

it means: “3 stars, 3 spaces, 3 stars, next line. 1 space, 3 stars, 1 space, 3 stars, next line. 2 spaces, 5 stars, next line. 3 spaces, 3 stars, next line. 4 spaces, 1 star, next line. Stop.”

And the printed output would look like this (assuming a fixed-width font):

***   ***
*** ***
*****
   ***
    *

Note that the commands themselves are not printed on the console -- just the output that is generated by the commands.

Details

The program must start at address x3000. Here’s how the program must behave:

1.      The program waits for a character to be typed on the keyboard. (Use GETC to read the character; it will be placed in R0.)

2.      If the character is a digit (‘0’ through ‘9’):

d)Convert the character to its corresponding decimal value. In other words, ‘0’ becomes zero, ‘1’ becomes 1, ... ‘9’ becomes 9. Let’s call that value R (for “run length”).

e)Wait for another character (using GETC).

f)Print R copies of that character to the console. (Use OUT to print one character, and do this R times. The character to be printed must be in R0 when OUT is called.)

g)Go back to Step 1.

3.      Else, if the character is Enter/Return (ASCII #10): Print a linefeed (ASCII #10) to the console, and go back to Step 1.

4.      Else, if the character is anything else, halt the program. (Use HALT.)

Explanation / Answer

.model small .code org 100h out start: mov cx, 5 out L1: push cx out L2: mov ah,2h mov dl,2Ah int 21h loop L2 mov dl,0Ah int 21h mov dl,0Dh int 21h pop cx loop L1 mov cx,5 out L3: push cx out L4: mov ah,2h mov dl,20h int 21h loop L4 out out mov dl,2Ah int 21h out mov dl,0Ah int 21h mov dl,0Dh int 21h pop cx out loop L3 out exit: int 20h end start