Question: Hello! If you could solve this Assembly Language Programming Question with comments on what each line does it'll be great! Thank you for your time!

Hello! If you could solve this Assembly Language Programming Question with comments on what each line does it'll be great! Thank you for your time!

CSP 025 Assembly Language L08

Introduction:

In this lab we will be rewriting the outNum routine from lab 6 so that we can right justify the numbers to make it look better.

Purpose:

The purpose of this lab is to rewrite the outNum routine to create a string. Then to output the string making the number look like it is moved to the right as we see in spreadsheets.

Write a program to print the sum of five decimal numbers. We will input digits until a CR is entered.

Example run:

Enter five numbers. End each number with a CR:

1

12

123

12

1

-----

149

New code sequence:

We will be changing the outNum routine to store the number in a string so we do not need the stack. We build the string from the right to left.

Getting started:

To be successful and learn the most, we always solve the problem logically first and then translate it into assembly language. We will always implement the logical solution as written.

1) Solve the problem with pseudocode. Notice that a "Print num" has been inserted after "Input num" in the main routine.

Start

Print "Enter five numbers. End each number with a CR:"

sum = 0

numCt = 0

WHILE numCt < 5

Input num

Print num

sum += num

numCt++

ENDWHILE

Print "----"

Print sum

Stop

inNum:

Enter

Num = 0

input Char

WHILE Char <> CR

dig = Cvt2Bin (Char)

Num = Num * 10 + dig

input Char

ENDWHILE

Exit

outNum:

Enter

numString[length] = 0

length--

Repeat

dig = num MOD 10

num = num / 10

numString[length] = Chr(dig)

length--

UNTIL num <= 0

WHILE length >= 0

numString[length] = ' '

length--

ENDWHILE

Print numString

Exit

2) Copy Project32 folder into your program folder. Rename it to Lab 8.

3) Put the pseudocode solution into our Lab 8 skeleton program. Update the comments to reflect the new program.

4) Now add assembly code. In .data add messages and variable locations. In .code translate pseudocode to assembly. We should do this in stages or "stub" test our program. First we will write the outNum routine and test it to print sum. After we know that it prints correctly then we will write the main and inNum routines. To do this 1) we put a value to print in sum (like 1234), 2) write code for the pseudocode that has only one semicolon in front of it in the main procedure, 3) write code for the outNum routine. We should only see the value of 1234 printed. After you see the value 1234 printed, then code the pseudocode with two semicolons in front. Change sum from 1234 to ?. Change double semicolons to a single semicolon.

TITLE Lab 8 (main.asm)

; Mel Simmons

; Description: Print sum of five numbers

; Assignment: Lab 8

; Date: 2/8/16

INCLUDE Irvine32.inc

CR EQU 13

LF EQU 10

.data

inMsg BYTE "Enter five numbers. End each number with a CR:", CR, LF, LF, 0

hyphens BYTE " ----", CR, LF, 0

sum DWORD 1234

num DWORD ?

numCt BYTE ?

.code

main PROC ;Start

call Clrscr

;;Print "Enter five numbers. End each number with a CR:"

;;Sum 0

;;NumCt = 0

main1:

;;WHILE NumCt < 5

;; Input num

;; mov AL, CR ; Print num

;; call WriteChar

;; mov EAX, num

;; mov ECX, 10

;; call outNum

call CRLF

;; sum += num

;; NumCt++

;; jmp main1

main2: ;ENDWHILE

;;Print "----"

mov AL, CR ;Print sum

call WriteChar

mov EAX, sum

mov ECX, 10

call outNum

call CRLF

exit ;Stop

main ENDP

;********************************

;TO USE

;Call inNum

;Return: Number in EAX

;REGISTER USE

;use EBX for Num

;use AL for Char

;use CL for dig

;********************************

;EBX will be used to create number and then moved to EAX

inNum PROC uses EBX ECX ;Enter

mov EBX, 0 ;num = 0

call ReadChar ;input char

inNum1: cmp AL, CR ;WHILE char <> CR

je inNum2

call WriteChar

movzx ECX, AL ; dig = Cvt2Bin (char)

sub CL, '0'

mov EAX, EBX ; num = num * 10 + dig

mov EBX, 10

mul EBX

add EAX, ECX

mov EBX, EAX

call ReadChar ; input char

jmp inNum1

inNum2: ;ENDWHILE

mov EAX, EBX

ret ;Exit

inNum ENDP

;********************************

;TO USE

; move number to print to EAX

; move size of number to print to ECX

; Call outNum

;REGISTER USE

; use EAX for Num

; use ECX for length

; use DL for dig

;********************************

.data

numString BYTE 15 DUP ('*'), 0

.code

outNum PROC uses EAX EBX ECX EDX ;Enter

mov numString [ECX], 0 ;numString[length] = 0

dec ECX ;length--

outNum1: ;Repeat

mov EBX, 10 ; dig = Num MOD 10

mov EDX, 0 ; Num = Num / 10

div EBX

add DL, '0' ; numString[length] = Chr(dig)

mov numString[ECX], DL

; length = length - 1

;UNTIL Num <= 0

outNum2:

;WHILE length >= 0

; numString[length] = ' '

; length = length - 1

jmp outNum2

outNum3: ;ENDWHILE

;Print numString

ret ;Exit

outNum ENDP

END main

5) Run program and correct any syntax errors.

__________________________________________________________________________

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!