Machine Level and Systems

Programming

Edo Biagioni esb@hawaii.edu

Department of Information and Computer Science

Today’s Outline

• Course Overview

• Motivation:

– what is assembly language programming?

– why is it interesting and important?

• SPARC

• Intel

• Compilers

Goals for the course

• learn to program computers at the machine/assembly level.

• learn SPARC assembly language programming.

• learn Intel x86 (Pentium+) assembly language programming.

• get an introduction to compilers.

Course Organization

• http://www.ics.hawaii.edu/˜ esb/- 1998fall.ics312/index.html

• lectures – overheads on web page 24 hours before class

• homeworks (approximately 40% of the grade)

• pop quizzes (approximately 20% of the grade)

• midterm and final (each approximately 20% of the grade)

• TA: Xiaowei Sun, xsun@hawaii.edu

• Office hours on web page

• Machine accounts (signup sheet)

Textbooks

• SPARC ”SPARC Architecture, Assembly Language Programming, and C”, by Richard P. Paul (Prentice Hall, 1994), available at the UH bookstore.

• Vol. 2 ”Intel Architecture Software Developer’s Manual, Volume 2: Instruction Set Reference”. Download from Web, or at campus copy center.

• Vol. 1 ”Intel Architecture Software Developer’s Manual, Volume 1: Basic Architecture”. Chapter 3 only. Download from Web, or at campus copy center.

DO NOT PRINT MANUALS ON ICS PRINTERS!

Use your own or ITS (Keller Hall), or buy from copy center.

Homeworks

• Assigned on Wednesday

• Due the following Wednesday • MUST be done individually

Quizzes

• Random days

• Test knowledge from lectures and textbook • 10 minutes at beginning of class

• Cannot be made up

Exams

• Midterm: Oct 15th.

• Final: December ???

• 50-minute tests.

Motivation

• Machine Language: bits and Bytes

• Assembly Language: symbols

• Fortran, C, C++, Java (3rd Generation languages): structured programming

• Application-specific languages, scripts (4th Generation languages)

• Compiler converts high-level language program to assembly code.

• Assembler converts assembly-language program to machine code.

Assembly Language

• Access to all capabilities of the machine – Registers

– Operations

• Not portable

• Operation codes (opcodes)

• Operands

• Program is a sequence of “Opcode, operands” lines

Example: Simple Calculator

• Opcodes are “+”, “-”, “*”, “/”

• Operands are constants (numbers) or accumulator

• Single register (the accumulator)

• ALU (Arithmetic Logic Unit) implements opcodes

• Need paper and pencil to compute

y = \frac{(x − 1)(x − 7)}{(x − 11)}

for x = 10.

Example: Stack Calculator

• Use a stack to store intermediate results (HP 15C)

•

y = \frac{(x − 1)(x − 7)}{(x − 11)}

– 10 enter
– 1 -
– 10 enter
– 7 -
– *
– 10 enter
– 11 -
– /

Notice how each line has an operand, and some lines have an opcode.

Example: Registers

Instead of x = 10, solve for x = 3.1415627. Entering data is tedious. Instead the value into register 0.

• 3.1415627 sto 0
• 1 -
• rcl 0
• 7 -
• *
• rcl 0
• 11 -
• /

Some instructions have two operands!

Example: Programmable Calculator

• A code (a number) represents each key.

• Codes are stored into memory

• Memory has an address (location) and data (value)

  char memory[1024];

• Value must be entered before program is executed

Program and Machine Code

Address Machine Code Assembly Program
000  44, 0  sto 0

002  1  1
003  30  -

004  45, 0  rcl 0

006  7  7
007  30  -
008  20  *

009  45, 0  rcl 0

011  1  1
012  1  1
013  30  -
014  10  /

015  43, 32  g Rtn

Machine Code

Store program on a disk:

44, 0, 1, 30, 45, 0, 7, 30, 20, 45, 0, 1,
1, 30, 10, 43, 32

Each assembly level instruction (e.g. “-”) always translates to the same opcode (30). This translation can be done by a program called an assembler.