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

Please use the Code template at the bottom. Objective The purpose of this assign

ID: 3603278 • Letter: P

Question

Please use the Code template at the bottom.

Objective

The purpose of this assignment is to familiarize students with the basics of LC3 assembly language programming, the SIMPL simulator, and rudimentary debugging.

High Level Description

Prompt the user to input two single digit numbers; the second will then be subtracted from the first, and the operation reported in the console:

<first number> - <second number> = <difference>

Low Level Breakdown:

This assignment comprises five tasks:

1. Prompt the user, and read two numeric characters ('0' ... '9') from the user using Trap x20 (GETC). Echo the characters to the console as they are input, and store them as character data in separate registers.

2. Output to the console the operation being performed e.g. 5 - 7 =

3. Using the same registers, convert the numeric characters into the actual numbers they represent (e.g. convert the ASCII code for ‘7’ into the binary representation of the number 7). 4. Perform the subtraction operation, and determine the sign (+/-) of the result; if negative, determine the magnitude of the result (i.e. take 2's complement)

5. Convert resulting number back to a printable character and print it, together with minus sign if necessary

Example algroithm:

1. Program prompts for user input, user enters ‘5’, which is echoed to console and stored in a register.

2. Program prompts for user input, user enters ‘7’, which is echoed to console and stored in a register.

3. Program outputs 5 - 7 =

4. Program converts ‘5’ into 5 and stores it back in the same register.

5. Program converts ‘7’ into 7 and stores it back in the same register.

6. Program performs (5-7) and stores the result, -2, in a register(obviously as a 2's complement number)

7. Program recognizes that result is negative, converts -2 to 2, and sets flag for minus sign

8. Program converts 2 into '2', and stores it back in same register

9. Program outputs the two characters -2 followed by a newline, thus completing the subtraction operation output

USET HIS CODE TEMPLATE

.ORIG x3000 ; Program begins here ;------------- ;Instructions ;------------- ;---------------------------------------------- ;outputs prompt ;---------------------------------------------- LEA R0, intro ; PUTS ; Invokes BIOS routine to output string ;------------------------------- ;INSERT CODE STARTING FROM HERE ;-------------------------------- HALT ; Stop execution of program ;------ ;Data ;------ ; String to explain what to input intro .STRINGZ "ENTER two numbers (i.e '0'....'9') " NEWLINE .STRINGZ " " ; String that holds the newline character ;--------------- ;END of PROGRAM ;--------------- .END

Explanation / Answer

.model small

.stack 100h

.data

prompt db 13, 10, 'First number:','$'

prompt db 13,10, 'Second number:', '$'

result db 13, 10, 'Sum','$'

;Variables

num1 db ?

num2 db ?

sum db ?

.code

main proc


mov ax,@data ;get data segment address

mov ds,ax ;initialize ds

;Display Prompt

mov ah,9 ;print string function

mov dx,offset prompt;ds:dx points to string

int 21h


; Numbers from the user

mov ah,1 ;input function

int 21h

mov bl,al ;save the value from input

mov num1,al

mov ah,9

lea dx, prompt ;print prompt

int 21h

mov ah,2 ;input second function

int 21h

mov bh,al ;save the value from second input

mov num2,al

;Addition

mov ax,num1 ;move num1 into ax

add ax,num2 ;add first and second numbers together

mov sum,ax ;move the total sum of numbers in sum

;Print Sum

mov ah,9

lea dx, result ; print result

int 21h

mov ah,2

mov dl,bl

int 21h

mov dl,'+' ;display + sign

int 21h

mov dl,bh

int 21h

mov dl,'=' ;display = sign

int 21h

mov dl,bh

int 21h

mov ah,4ch

int 21h

main endp

end main