Comp 255 - Computer Organization Lab 07 The HACK Assembly Language



Similar documents
4 Machine Language. Make everything as simple as possible, but not simpler. Albert Einstein ( )

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Notes on Assembly Language

1 Description of The Simpletron

Adding and Subtracting Positive and Negative Numbers

The Little Man Computer

Mistakes are the portals of discovery. James Joyce ( )

Summary of the MARIE Assembly Language

Lab Experience 17. Programming Language Translation

1 Classical Universal Computer 3

Fall 2006 CS/ECE 333 Lab 1 Programming in SRC Assembly

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

LC-3 Assembly Language

X86-64 Architecture Guide

Figure 1: Graphical example of a mergesort 1.

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Process / Operation Symbols

Instruction Set Design

VB.NET Programming Fundamentals

Here is a diagram of a simple computer system: (this diagram will be the one needed for exams) CPU. cache

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Administrative Issues

MACHINE ARCHITECTURE & LANGUAGE

(Cat. No L3) Product Data

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

What to do when I have a load/store instruction?

OAMulator. Online One Address Machine emulator and OAMPL compiler.

UT69R000 MicroController Software Tools Product Brief

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Chapter 9 Computer Design Basics!

In this Chapter you ll learn:

CPU Organization and Assembly Language

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Instruction Set Architecture

Instruction Set Architecture

Instruction Set Architecture (ISA)

Introduction to Microcontrollers

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

Database Programming with PL/SQL: Learning Objectives

2) Write in detail the issues in the design of code generator.

A Tiny Guide to Programming in 32-bit x86 Assembly Language

Writing Control Structures

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

PART B QUESTIONS AND ANSWERS UNIT I

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

Parameter Passing in Pascal

Levels of Programming Languages. Gerald Penn CSC 324

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

Chapter 7D The Java Virtual Machine

11 November

DATA ITEM DESCRIPTION

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Visual Logic Instructions and Assignments

We will use the accumulator machine architecture to demonstrate pass1 and pass2.

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

Lecture 22: C Programming 4 Embedded Systems

Embedded Software development Process and Tools:

The 104 Duke_ACC Machine

Flowchart Techniques

HC12 Assembly Language Programming

F B = ilbsin(f), L x B because we take current i to be a positive quantity. The force FB. L and. B as shown in the Figure below.

EC 362 Problem Set #2

MACHINE INSTRUCTIONS AND PROGRAMS

Systems I: Computer Organization and Architecture

E-Blocks Easy Internet Bundle

Faculty of Engineering Student Number:

Floating Point C Compiler: Tips and Tricks Part I

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

6. Control Structures

Where we are CS 4120 Introduction to Compilers Abstract Assembly Instruction selection mov e1 , e2 jmp e cmp e1 , e2 [jne je jgt ] l push e1 call e

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

IBCM: The Itty Bitty Computing Machine

8051 MICROCONTROLLER COURSE

CSE 141L Computer Architecture Lab Fall Lecture 2

Progressing toward the standard

Chapter 7 Assembly Language

CPU Organisation and Operation

A LEVEL H446 COMPUTER SCIENCE. Code Challenges (1 20) August 2015

Computer Organization and Architecture

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

Regression Verification: Status Report

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

Review: MIPS Addressing Modes/Instruction Formats

Chapter 5. Selection 5-1

Computer Programming I

MICROPROCESSOR AND MICROCOMPUTER BASICS

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

A s we saw in Chapter 4, a CPU contains three main sections: the register section,

Character Translation Methods

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Chapter 4 Macro Processors -- Basic Macro Processor Functions

13 Classes & Objects with Constructors/Destructors

Chapter 2 Assemblers

Transcription:

Comp 255 - Computer Organization Lab 07 The HACK Assembly Language February 26, 2013 Name: Grade: /10 Begin by opening the two ECS applications Assembler.bat and CPUEmulator.bat; the former will be used to assemble HACK assembly language programs (.asm files) into HACK machine code (.hack files) to be executed by the CPUEmulator application. 1a. A simple addition program A. Using NotePad create the following file. Call it Lab09a.asm // // Name: // File: Lab09a.asm // Date: February 26, 2013 // Desc: A simple addition program for the HACK computer // @R1 (END) Notes: D=M // load R1 @R2 D=D+M // R1 + R2 @R3 M=D // store in R3 // label @END 0;JMP // Infinite loop a. R1, R2, and R3 refer to memory locations 1 3 (RAM[1] RAM[3]). b. Since there is no halt instruction in Hack assembly language the last two instructions sends the program into an infinite loop B. Assemble this source code file into an object code file called Lab09a.hack C. Load Lab09a.hack into the CPUEmulator. Initialize memory locations 1 and 2 to 2 and 3 respectively Run (Step) the code. If successful you should see the value 5 appear at address 3. D. Print out your Lab07a.asm file and your Lab07a.Hack file to be handed in. Lab07-1

1b Run the same program using a.tst file: When done this way the Assembler is automatically invoked by the.tst script which also initializes RAM locations (variables). Since compare and output files are not used their corresponding lines have been commented out. D. Using NotePad create following.tst file. load lab07a.asm, //output-file lab07a.out, //compare-to lab07a.cmp, //output-list RAM[3]%D2.6.2; Set PC 0; set RAM[1] 2; set RAM[2] 3; //output E. Run this.tst script from the CPUEmulator application 1.c Optional Version: The alternate version of Lab09a.asm below allocated three variables a, b, and c (instead of R1, R2, an R3). The assembler would allocate locations RAM[16], RAM[17] and RAM[18] respectively for each. The.tst file is altered to initialize a and b. Name the source code file Lab09a1.asm... // Desc: A simple addition program // (END) D=M // load a @b D=D+M // a + b @c M=D // store in c // label @END 0;JMP // Infinite loop The corresponding alternate.tst file load lab09a.asm, //output-file lab09a.out, //compare-to lab09a.cmp, //output-list RAM[18]%D2.6.2; set PC 0; set RAM[16] 2; set RAM[17] 3; //output Lab07-2

2. A simple subtraction program: Write and execute a Hack assembly language program to subtract R2 from R1 putting the difference in R3. Call it Lab09b.asm Modify Lab07a.tst to test Lab07b.asm. Call it Lab07b.tst Run the Lab07b.tst script in the CPUEmulator to execute Lab07b.asm. When it successfully runs print out the source code file Verification #2: 3. Unconditional and Conditional Branching Unconditional branching is done by setting A to the target address (a label) followed by 0; JMP @label 0; JMP // jump always Conditional branching can be done by testing the contents of the D register and jumping if the condition is met (in a sense this is similar to how the PDP-8 does it) @target D;JEQ // jump to target if D = 0 Write and test a simple Hack assembly language program that given two registers R1 and R2 subtracts the smaller from the larger putting the result in R3. Call it Lab09c.asm. Test your program using the following.tst code. Note that this.tst file generates an output file (Lab09c.out) which will allow you to check your results. (Note that the CPUEmulator can display an output file) load lab07c.asm, output-file lab07c.out, //compare-to lab07c.cmp, output-list RAM[3]%D2.6.2; Set PC 0; set RAM[1] 2; set RAM[2] 7; output; set PC 0; set RAM[1] 5; set RAM[2] 3; output; Lab07-3

Run the Lab07c.tst script in the CPUEmulator to execute Lab07c.asm. When it successfully runs print out the source code file Verification #3: 4 Loops: Write a program to sum the integers between K and N inclusive (you may assume k < n). Use R1 to hold K, R2 to hold N and put the SUM R3. Allocate other variables or registers as needed. Probably the easiest way to program this is to a. allocate a loop counter variable I b initialize I to K c. add I to SUM d. add 1 to I e subtract I from N f test: tf you store the results in register D then the conditional branch instruction @StepC D; JGE should work. Call your program Lab07d.asm Create an appropriate Lab09d.tst script and run it in the CPUEmulator to execute Lab09d.asm. When it successfully runs print out the source code file Verification #4: Hand In: Source code files Lab07a.asm, Lab07b.asm, Lab07c.asm, Lab07d.asm (Lab07a1.asm was optional) Test file Lab07d.tst Lab07-4

An Overview of Hack Assembly Language The Hack instruction set has two instruction format: a A-instruction which loads the A register with an immediate value and a C-instruction which is a combined compute and optionally branch instruction. Most instructions are C-instructions A-instruction: set contents of Address Register @value // A value C-instruction: Compute & (optionally) Branch dest = comp ; jump // comp is required where comp is one of 0, 1, -1, D, A,!D,!A, -D, -A, D+1, A+1, D-1, A-1 M,!M, -M, M+1, M-1 D+A, D-A, A-D, D&A, D A D+M, D-M, M-D, D&M, D M Note M refers to Mem[A] dest is one of jump is one of null, M, D, MD, A, AM, AD, AMD null, JGT, JEQ, JGE, JLT, JNE, JLE, JMP where A holds target address for the jump if taken; The condition is determined by a results of the comp operation. Directives & Conventions (label) // label Predefined Symbols: R0 thru R15 are RAM locations 0 thru 15 The assembler allocates storage for variables beginning at RAM location 16; the programmer has no control over storage allocation. Storage is allocated as each variable is encountered. Lab07-5

Examples and Techniques To set D to a constant value @17 // A = 17 D = A // D = A Accessing Memory: Load D from a D = M // D = a Accessing Memory: Store D to a M = D // a = D Accessing Memory: Load R0 from a D = M @R0 M = D // D = a // get address R0 // R0 = D Accessing Memory: Store R0 to a @R0 D = M M = D // get address R0 // D = R0 // a = D Unconditional Jump @END // get address END (a label) 0; JMP // jump always to END Conditional Jump branch to L1 on D = 0 To initialize a variable @L1 // get address L1 (a label) D; JEQ // jump if D == 0 to L1 @17 // A = 17 D = A // D = A M = D // a = D Lab07-6