# Overview - PowerPoint PPT Presentation

1 / 13
Title:

## Overview

Description:

### console, and pack them into a file (2 characters per word) Flow Diagram. Machine code ... SIX .FILL x0006 .END. Assembler Directives. Pseudo-operations ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 14
Provided by: larry109
Category:
Tags:
Transcript and Presenter's Notes

Title: Overview

1
Overview
• Problem 5.33
• Machine Language Programming Exercises
• Introduction to Assembly Language Programming
• Examples of Assembly Language Programming
• Writing Assembly Language Programming.

2
Homework Problem 5.33
• The instructions are
• x3000 AND R7, R7, 0 R7 lt-0
• x3001 ADD R6, R7, 1 R6 lt-1
• x3002 AND R4, R5, R6 Uses R6 as mask
to tests one bit of R5 for a 1
• x3003 BRZ x3005 Skips x3004 if
bit in R5 was not a 1
• x3004 ADD R0, R0, 1 Increments R0 if
tested bit in R5 was a 1
• x3005 ADD R6, R6, R6 Moves test bit of
R6 to left
• x3007 ADD R7, R7, 1 Increments R7
• x3008 ADD R1, R7, -8 R1 is 7, -6,
-5, -4, -3, -2, -1, 0
• x3009 BRN x3002 Loops back 7
times, i.e. tests lowest 8 bits of R5
• The number in R0 increases by the number of 1s
in R5. If R0 was initially 0, then R0
• being 5 after completion means that there were
five 1s in the lower 8 bits of R5.
• If the value in R0 was initially N, then there
were 5-N 1s in the lower 8 bits of R5.

3
• Programming Exercise 1
• Write a program to count the 1s in register R0
• Flow Diagram
• Machine code

4
• Programming Exercise 2
• Write a program to add the contents of R0 and R1,
and indicate in R2 if there
• was an overflow
• Flow Diagram
• Machine code

5
• Programming Exercise 3
• Write a program to Divide the contents of R0 by
the contents of R1
• Flow Diagram
• Machine code

6
• Programming Exercise 4
• Write a program to read characters from the
keyboard, echo them on the
• console, and pack them into a file (2 characters
per word)
• Flow Diagram
• Machine code

7
LC-3 Assembly Language Syntax
• Each line of a program is one of the following
• an instruction
• an assember directive (or pseudo-op)
• a comment
• Whitespace (between symbols) and case are
ignored.
• Comments (beginning with ) are also ignored.
• An instruction has the following format

optional
mandatory
8
An Assembly Language Program
• Program to multiply a number by the constant 6
• .ORIG x3050
• LD R1, SIX
• LD R2, NUMBER
• AND R3, R3, 0 Clear R3. It will
• contain the product.
• The inner loop
• AGAIN ADD R3, R3, R2
• ADD R1, R1, -1 R1 keeps track of
• BRp AGAIN the iteration.
• HALT
• NUMBER .BLKW 1
• SIX .FILL x0006

9
Assembler Directives
• Pseudo-operations
• do not refer to operations executed by program
• used by assembler
• look like instruction, but opcode starts with
dot

10
Trap Codes
• LC-3 assembler provides pseudo-instructions
foreach trap code, so you dont have to remember
them.

11
Sample Program
• Count the occurrences of a character in a
file.Remember this?

12
Count the occurrences of a character in a file (1
0f 2).
• Program to count occurrences of a character in
a file.
• Character to be input from the keyboard.
• Result to be displayed on the monitor.
• Program only works if no more than 9
occurrences are found.
• Initialization
• .ORIG x3000
• AND R2, R2, 0 R2 is counter, initially 0
• LD R3, PTR R3 is pointer to character file
• GETC R0 gets input character
• LDR R1, R3, 0 R1 gets first character from
file
• Test character for end of file
• TEST ADD R4, R1, -4 Test for EOT (ASCII x04)
• BRz OUTPUT If done, prepare the output

13
Count the occurrences of a character in a file (2
of 2).
• Output the count.
• OUTPUT LD R0, ASCII Load the ASCII template
• ADD R0, R0, R2 Covert binary count to ASCII
• OUT ASCII code in R0 is displayed.
• HALT Halt machine
• Storage for pointer and ASCII template
• ASCII .FILL x0030 ASCII offset
• PTR .FILL x4000 PTR to character file
• .END