+ All Categories
Home > Documents > TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Date post: 13-Jan-2016
Category:
Upload: erika-stokes
View: 218 times
Download: 0 times
Share this document with a friend
72
TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”
Transcript
Page 1: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

TCSS 490A Topics in Computing & Software Systems

“Introduction to Computer Systems”

Page 2: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

What do we want to do tonight ?

First:

• Get acquainted

• Review the syllabus

• Understand the scope, purpose, and expectations of the course

• Check out our textbook

• Visit our Laboratory (CP 206C)

Page 3: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

What do we want to do tonight ?Second:

• Discuss the levels of abstraction involved in a computer solution to problem

• Discuss major Numeric Data Types

• Develop expertise in working with various numeric bases

especially base 10, base 2 (binary), and base 16 (hexidecimal)

• Become proficient converting numbers from one base to another

• Become proficient with 2’s complement arithmetic

• Understand round off error, sign extension, and overflow

• Understand representation of floating point numbers

• Understand Binary Logic

Page 4: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

The levels of abstraction involved in a computer solution to problem

• Problem

• Algorithm

• Language

• Machine Architecture

• Microarchitecture

• Circuits

• Devices

• Electron or light flow

Page 5: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Develop expertise in working with various numeric bases

• Base 10

• Base 2 (binary)

• Base 16 (hexidecimal)

• Others ?

Page 6: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Become proficient converting numbers from one base to another

• Base 10 to binary

• Binary to Base 10

• Base 10 to Hexidecimal

• Hexidecimal to Base 10

• Binary to Hexidecimal

• Hexidecimal to Binary

• Others ?

Page 7: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Major Numeric Data Types

• Unsigned Integers

• Signed Integers

• 2’s Complement Integers

• Floating Point Numbers

Page 8: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Become proficient with 2’s complement arithmetic

(See Text Figure 2.1)

• Signed Binary Integers

• 1’s Complement Binary Integers

• 2’s complement Binary Integers

Page 9: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Binary Arithmetic

• Unsigned add & subtract

• 2’s complement add & subtract

Page 10: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Understand round off error, sign extension, and overflow

• overflow

• sign extension

• Binary fractions (the binary point)

• round off error

Page 11: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Understanding Floating Point NumbersIEEE Standard

• sign (1 bit), exponent (8 bits), fraction (23 bits)

(-1)**sign x 1.fraction x 2**exponent-127

1<= exponent <= 254

Page 12: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

ASCII (7 bit or extended)UNICODE (16 bit)

• See ASCII table

• See UNICODE table

Page 13: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Binary Logic

• NOT

• AND (NAND)

• OR (NOR)

• XOR

• Truth tables

• DeMorgan’s Theorem

Page 14: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

What do we want to do tonight ?(Second Week)

• Introduce logic circuits

• Relay logic

• MOS semiconductors

• Inverter

• Nor Gate

• Nand Gate

• Combinational Logic

• Decoders

• Full Adder

• PLA’s

• MUX – Multiplexers

Page 15: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

What do we want to do tonight ?

•Storage Devices

• SR Flip-Flops

• D Latch Flip Flops

• J/K Master Slave Flip Flops

• Registers

• Addressing

• Finite State Machines

• State Diagrams

Page 16: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

The LC-3 as a von Neumann machine

Page 17: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Data Path of the LC-3

Page 18: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

The Instruction

FORMAT

•Operation code

• Input Operand(s)

• Output Operand(s)

ADDRESSING MODES

• Register

•PC-relative

•Base + Offset (Base relative)

•Immediate

•Indirect

Page 19: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Operate Instructions

• Only three operations: ADD, AND, NOT

• Source and destination operands are registers

Page 20: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

ADD/AND (Register)

Page 21: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

NOT (Register)

Note: Src and Dstcould be the same register.

Page 22: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

ADD/AND (Immediate)

Note: Immediate field issign-extended.

Page 23: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Data Movement Instructions•Load -- read data from memory to register

– LD: PC-relative mode [0010 DR PCoffset9]– LDI: indirect mode [1010 DR PCoffset9]– LDR: base+offset mode [0110 DR BaseR offset6]

•Store -- write data from register to memory– ST: PC-relative mode [0011 DR PCoffset9]– STI: indirect mode [1011 DR PCoffset9]– STR: base+offset mode [0111 DR BaseR offset6]

•Load effective address – address saved in register– LEA: immediate mode [1110 DR PCoffset9]

Page 24: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

LD (PC-Relative)

Page 25: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

ST (PC-Relative)

Page 26: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

LDI (Indirect)

Page 27: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

STI (Indirect)

Page 28: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

LDR (Base+Offset)

Page 29: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

STR (Base+Offset)

Page 30: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

LEA (Immediate)

Page 31: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Branch Instruction

BR [0000 nzp PCoffset9]

• Branch specifies one or more condition codes• If the set bit is specified, the branch is taken:

– PC is set to the address specified in the instruction

– Target address is made by adding SEXT(IR[8:0]) to the PC

• If the branch is not taken: - the next sequential instruction (PC) is executed.

Page 32: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

BR

/////////////

///// +

SEXT

Page 33: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Jump Instruction

JMP BaseR [1100 000 BaseR 000000]

• Jump is an unconditional branch -- always taken.

• Base– Address is contents of the register– Allows any target address.

Page 34: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

TRAP

• Calls a service routine, identified by 8-bit “trap vector.”

• When routine is done, PC is set to the instruction following TRAP.

vector routine

x23 input a character from the keyboard

x21 output a character to the monitor

x25 halt the program

Page 35: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Example 1: Multiply• This program multiplies two unsigned

integers in R4 and R5.

x3200 0101010010100000x3201 0001010010000100x3202 0001101101111111x3203 0000011111111101x3204 1111000000100101

clear R2

add R4 to R2

decrement R5

R5 = 0?

HALT

No

Yes

R2 <- 0R2 <- R2 + R4 R5 <- R5 – 1BRzp x3201HALT

Page 36: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

ExampleAddress Instruction Comments

x30F6 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 R1 PC – 3 = x30F4

x30F7 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 R2 R1 + 14 = x3102

x30F8 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1M[PC - 5] R2

M[x30F4] x3102

x30F9 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 0

x30FA 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 R2 R2 + 5 = 5

x30FB 0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 0M[R1+14] R2M[x3102] 5

x30FC 1 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1R3 M[M[x30F4]]

R3 M[x3102]

R3 5

Opcode

Page 37: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Using Branch Instructions• Compute sum of 12 integers.

Numbers start at location x3100. Program starts at location x3000.

R1 x3100R3 0R2 12

R2=0?

R4 M[R1]R3 R3+R4R1 R1+1R2 R2-1

NO

YES

Page 38: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Sample ProgramAddress Instruction Comments

x3000 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 R1 x3100

x3001 0 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 R3 0

x3002 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 0

x3003 0 0 0 1 0 1 0 0 1 1 1 0 1 1 0 0 R2 12

x3004 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 If Z, goto x3009

x3005 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 Load next value to R4

x3006 0 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1 Add to R3

x3007 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 Increment R1 (pointer)

X3008 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 Decrement R2 (counter)

x3009 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 Goto x3004

Page 39: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Flow Chart

Count = 0(R2 = 0)

Ptr = 1st file character(R3 = M[x3012])

Input charfrom keybd

(TRAP x23)

Done?(R1 ?= EOT)

Load char from file(R1 = M[R3])

Match?(R1 ?= R0)

Incr Count(R2 = R2 + 1)

Load next char from file(R3 = R3 + 1, R1 = M[R3])

Convert count toASCII character

(R0 = x30, R0 = R2 + R0)

Print count(TRAP x21)

HALT(TRAP x25)

NO

NO

YES

YES

Page 40: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Program (1 of 2)Address Instruction Comments

x3000 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 0 (counter)

x3001 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 R3 M[x3102] (ptr)

x3002 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 Input to R0 (TRAP x23)

x3003 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1 M[R3]

x3004 0 0 0 1 1 0 0 0 0 1 1 1 1 1 0 0 R4 R1 – 4 (EOT)

x3005 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 If Z, goto x300E

x3006 1 0 0 1 0 0 1 0 0 1 1 1 1 1 1 1 R1 NOT R1

x3007 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 R1 R1 + 1

X3008 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 R1 R1 + R0

x3009 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 If N or P, goto x300B

Page 41: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Program (2 of 2)Address Instruction Comments

x300A 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 R2 R2 + 1

x300B 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 R3 R3 + 1

x300C 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1 M[R3]

x300D 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 Goto x3004

x300E 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 R0 M[x3013]

x300F 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 R0 R0 + R2

x3010 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 Print R0 (TRAP x21)

x3011 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 HALT (TRAP x25)

X3012 Starting Address of File

x3013 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 ASCII x30 (‘0’)

Page 42: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Filled arrow = info to be processed.

Unfilled arrow= control signal.

Page 43: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Three Basic Constructs

• There are three basic ways to decompose a task:

Task

Subtask 1

Subtask 2Subtask 1 Subtask 2

Testcondition

Subtask

Testcondition

Sequential Conditional Iterative

True

True

FalseFalse

Page 44: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

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:

LABEL OPCODE OPERANDS ; COMMENTS

optional mandatory

Page 45: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

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•;• .END

Page 46: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Assembler Directives• Pseudo-operations

– do not refer to operations executed by program– used by assembler– look like instruction, but “opcode” starts with dot

Opcode Operand Meaning.ORIG address starting address of program

.END end of program

.BLKW n allocate n words of storage

.FILL n allocate one word, initialize with value n

.STRINGZ n-character string

allocate n+1 locations, initialize w/characters and null terminator

Page 47: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Trap Codes• LC-3 assembler provides “pseudo-instructions” for

each trap code, so you don’t have to remember them.

Code Equivalent Description

HALT TRAP x25 Halt execution and print message to console.

IN TRAP x23 Print prompt on console,read (and echo) one character from keybd.Character stored in R0[7:0].

OUT TRAP x21 Write one character (in R0[7:0]) to console.

GETC TRAP x20 Read one character from keyboard.Character stored in R0[7:0].

PUTS TRAP x22 Write null-terminated string to console.Address of string is in R0.

Page 48: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Sample Program• Count the occurrences of a character in a file.

Remember this?

Count = 0(R2 = 0)

Ptr = 1st file character(R3 = M[x3012])

Input charfrom keybd

(TRAP x23)

Done?(R1 ?= EOT)

Load char from file(R1 = M[R3])

Match?(R1 ?= R0)

Incr Count(R2 = R2 + 1)

Load next char from file(R3 = R3 + 1, R1 = M[R3])

Convert count toASCII character

(R0 = x30, R0 = R2 + R0)

Print count(TRAP x21)

HALT(TRAP x25)

NO

NO

YES

YES

Page 49: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Char Count in Assembly Language (1 of 3)

•;•; 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 characters• GETC ; R0 gets character input• LDR R1, R3, #0 ; R1 gets first character•;•; Test character for end of file•;•TEST ADD R4, R1, #-4 ; Test for EOT (ASCII x04)• BRz OUTPUT ; If done, prepare the output

Page 50: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Char Count in Assembly Language (2 of 3)

•;•; Test character for match. If a match, increment count.•;• NOT R1, R1• ADD R1, R1, R0 ; If match, R1 = xFFFF• NOT R1, R1 ; If match, R1 = x0000• BRnp GETCHAR ; If no match, do not increment• ADD R2, R2, #1•;•; Get next character from file.•;•GETCHAR ADD R3, R3, #1 ; Point to next character.• LDR R1, R3, #0 ; R1 gets next char to test• BRnzp TEST•;•; 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

Page 51: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Char Count in Assembly Language (3 of 3)

•;•; Storage for pointer and ASCII template•;•ASCII .FILL x0030•PTR .FILL x4000• .END

Page 52: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Program to find number of negative numbers

1. Initialize Registers

2. Get next data

3. If sign is negative, increment count

4. Update data pointer

5. If not done, go to 2.

6. Store result

7. Halt

Page 53: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Program to find number of negative numbers

1. Initialize Registers R0 = Counter of neg numbers R1 = Sign Mask R2 = Number of Data words R3 = Ptr to Data R4 = Data buffer

2. Get next data Load R4 with (R3)

3. If sign is negative, increment count AND Sign Mask with Data, Inc R0 if not zero

4. Update data pointer Inc R3 Dec R2

5. If not done, go to 2. IF Positive go to 2.

6. Store result Store R0 in location pointed to by result pointer

7. Halt

Page 54: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Program to find number of negative numbers

.ORIG x3000;; Initialze Registers;

AND R0, R0, #0 ; Clr counter of negative numbersLD R1, MASK ; Set sign bit maskADD R2, R0, #10; Set # of Data wordsLD R3, PTR_DATA; Set Data Ptr

;; Loop to check words;LOOP LDR R4, R3, #0 ; Fetch data word

AND R4, R4, R1 ; Test for sign bitBRz NEXT ; ADD R0, R0, #1 ; Inc counter if negative

NEXT ADD R3, R3, #1 ; Inc Data PtrADD R2, R2, #-1 ; Dec # of Data words leftBRp LOOP

;; Store Result;

STI R0, PTR_RESULT; Store result in 4010HALT

;; Data;MASK .FILL x8000PTR_DATA .FILL x3020PTR_RESULT .FILL x3040 .END

Page 55: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Assembly Language Instructions

1) Move data InstructionsReg Reg ADD, ANDReg Memory LD, LDR, LDIMemory Reg ST, STR, STIClear REG AND LOAD ADDRESS LEA

1) Computation – Arithmetic and Logic Arithmetic ADDLOGIC AND, NOT, (SHIFT)

2) Program Control – support IF, WHEN, DO BR

JMP

3) Subroutines (& Methods) - Pass Parameters – by value, by reference, Stack

JSR JSRR RET

4) Trap – operating system support - StackTRAPRET

5) Interrupts – Status Reg / Hardware does the “call”. Priorities, PSR, Supervisor Stack

RTI

Page 56: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Addressing

1) Register – operand is in a register

2) Immediate (or literal) – operand is in IR[5:0]

3) PC Relative – operand is in PC+IR[8:0]ext or PC+IR[10:0]ext

4) Base + Offset – operand is in BaseReg or BaseReg+IR[5:0]

5) Indirect – operand address is at PC+IR[8:0]

Page 57: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Hardware

1) Arithmetic and Logic Unit – Nominally 2 operands

2) Memory - Memory Address Register (MAR) & Memory Data Register (MDR)

3) Registers (R0-R7) – Convention R0, R5, R6, R7

4) Program Counter (PC) – Incremented after instruction fetch!

4) Instruction Register (IR) – Hold Instruction being executed

5) Processor Status Register (PSR) – Privileged, Priority, CC’s

6) Stack Pointer Storage Regs – Saved.SysStackPtr & Saved.UserStackPtr

7) I/O DevicesDevice Data Register(s)Device Status Register(s) – Ready Bit, Intr Enable Bit, Priority?

Page 58: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Traps

1) Execute TRAP “vector” - Operating System Service Routines

2) Trap Vectors are at memory locations [0000:00FF]

3) Trap Vectors contain addresses of Trap Service Routines

4) (PC) is loaded into R7

5) Address of Trap Service Routine loaded into PC

6) Service Routine Program executed

7) Trap service routine program ends with an RET ( (R7) loaded into PC)

Page 59: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Subroutines

1) Execute JSR or JSRR - Call Subroutine or Method

2) Location of Subroutine is “in” the Instruction

4) (PC) stored in R7

5) Address from JSR or JSRR is loaded into PC

6) Subroutine is executed R0 possibly contains passed parameter (or address)Stack may contain passed parameters (or addresses)R5 may be used to return error messageRo possibly contains return parameter (or address)Stack may contain return parameters (or addresses)

7) Subroutine program ends with an RET( (R7 loaded into PC)

How does this mechanism support recursion?

Page 60: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Interrupts1) Enable Interrupts by setting “intr enable” bit in Device Status Reg

2) When device ready bit is set and the priority is higher than the priority of the presently running program (and execution of an instruction is complete) the processor initiates the interrupt

4) The Processor saves the “state” of the programThe Processor goes into Privileged Mode PSR bit 15 cleared Priority level is set (likely established by the interrupting

device) The CC’s are cleared (R6) is stored in USP.saved registerThe Supervisor Stack Ptr is loaded into R6The (PC) and the (PSR) are PUSHED onto the Supervisor StackThe contents of the other registers are not saved. Why?

5) The Processor Loads the PC from the Interrupt vector (vectors in 100:1FF)

6) Interrupt Service Routine is executedEnds with an RTI

7) The stored user PSR, PC, and R6 are reloaded and the next instruction executed(POPS top of stack into PC)

Page 61: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Higher Level Languages

High Level Languages give us:

• Symbolic Names

• Expressions

• Libraries of functions/subroutines

• Abstraction of underlying hardware

• Readability

• Structure – help keep bugs out

Page 62: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

First C Program/* * Program Name : countdown, our first C program * * Description : This program prompts the user to type in * a positive number and counts down from that number to 0, * displaying each number along the way. */

/* The next two lines are preprocessor directives */

#include <stdio.h> #define STOP 0

/* Function : main *//* Description : prompt for input, then display countdown */

int main(){ /* Variable declarations */

int counter; /* Holds intermediate count values */ int startPoint; /* Starting point for count down */ /* Prompt the user for input */

printf("===== Countdown Program =====\n"); printf("Enter a positive integer: "); scanf("%d", &startPoint); /* Count down from the input number to 0 */

for (counter = startPoint; counter >= STOP; counter--) { printf("%d\n", counter); }

return 0}

Page 63: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Compiling C

Page 64: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Terms• Pre processor directives

#define#include

• Header Files<stdio.h>

• Data Typesintchardouble

• ScopeLocalGlobal

• Variable initiation

Page 65: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Scope#include <stdio.h>

int globalVar = 2; /* This variable is global */

int main(){ int localVar = 3; /* This variable is local to main */ printf("Global %d Local %d\n", globalVar, localVar); { int localVar = 4; /* Local to this sub-block */ printf("Global %d Local %d\n", globalVar, localVar); } printf("Global %d Local %d\n", globalVar, localVar);

return 0}

Page 66: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program#include <stdio.h>

int main(){ int amount; /* The number of bytes to be transferred */ int rate; /* The average network transfer rate */ int time; /* The time, in seconds, for the transfer */

int hours; /* The number of hours for the transfer */ int minutes; /* The number of mins for the transfer */ int seconds; /* The number of secs for the transfer */

/* Get input: number of bytes and network transfer rate */ printf("How many bytes of data to be transferred? "); scanf("%d", &amount); printf("What is the transfer rate (in bytes/sec)? "); scanf("%d", &rate);

/* Calculate total time in seconds */ time = amount / rate;

/* Convert time into hours, minutes, seconds */ hours = time / 3600; /* 3600 seconds in an hour */ minutes = (time % 3600) / 60; /* 60 seconds in a minute */ seconds = ((time % 3600) % 60); /* remainder is seconds */ /* Output results */ printf("Transfer Time : %dh %dm %ds\n", hours, minutes, seconds);

return 0}

Page 67: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program/* Include the standard I/O header file */#include <stdio.h>

int inGlobal; /* inGlobal is a global variable because */ /* it is declared outside of all blocks */

int main() { int inLocal; /* inLocal, outLocalA, outLocalB are all */ int outLocalA; /* local to main */ int outLocalB; /* Initialize */ inLocal = 5; inGlobal = 3; /* Perform calculations */ outLocalA = inLocal & ~inGlobal; outLocalB = (inLocal + inGlobal) - (inLocal - inGlobal); /* Print out results */ printf("outLocalA = %d, outLocalB = %d\n", outLocalA, outLocalB);

return 0}

Page 68: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program

#include <stdio.h>

#define RADIUS 15.0 /* This value is in centimeters */

int main()

{

const double pi = 3.14159;

double area;

double circumference;

/* Calculations */

area = pi * RADIUS * RADIUS; /* area = pi*r^2 */

circumference = 2 * pi * RADIUS; /* circumference = */

/* 2*pi*r */

printf("Area of a circle with radius %f cm is %f cm^2\n",

RADIUS, area);

printf("Circumference of the circle is %f cm\n",

circumference);

return 0

}

Page 69: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another programint main()

{

char nextChar; /* Next character in email address */

int gotAt = FALSE; /* Indicates if At @ was found */

int gotDot = FALSE; /* Indicates if Dot . was found */

printf("Enter your email address: ");

do {

scanf("%c", &nextChar);

if (nextChar == '@')

gotAt = TRUE;

if (nextChar == '.' && gotAt == TRUE)

gotDot = TRUE;

}

while (nextChar != ' ' && nextChar != '\n');

if (gotAt == TRUE && gotDot == TRUE)

printf("Your email address appears to be valid.\n");

else

printf("Your email address is not valid!\n");

return 0

}

Page 70: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program#include <stdio.h>

#define FALSE 0

#define TRUE 1

int main()

{

char nextChar; /* Next character in email address */

int gotAt = FALSE; /* Indicates if At @ was found */

int gotDot = FALSE; /* Indicates if Dot . was found */

printf("Enter your email address: ");

do {

scanf("%c", &nextChar);

if (nextChar == '@')

gotAt = TRUE;

if (nextChar == '.' && gotAt == TRUE)

gotDot = TRUE;

}

while (nextChar != ' ' && nextChar != '\n');

if (gotAt == TRUE && gotDot == TRUE)

printf("Your email address appears to be valid.\n");

else

printf("Your email address is not valid!\n");

return 0

}

Page 71: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program#include <stdio.h>

#define FALSE 0

#define TRUE 1

int main()

{

char nextChar; /* Next character in email address */

int gotAt = FALSE; /* Indicates if At @ was found */

int gotDot = FALSE; /* Indicates if Dot . was found */

printf("Enter your email address: ");

do {

scanf("%c", &nextChar);

if (nextChar == '@')

gotAt = TRUE;

if (nextChar == '.' && gotAt == TRUE)

gotDot = TRUE;

}

while (nextChar != ' ' && nextChar != '\n');

if (gotAt == TRUE && gotDot == TRUE)

printf("Your email address appears to be valid.\n");

else

printf("Your email address is not valid!\n");

return 0

}

Page 72: TCSS 490A Topics in Computing & Software Systems “Introduction to Computer Systems”

Another program; Program to compute z = x * Y; (R5) -> X , (R5)-1 -> Y;

AND R0, R0, #0 ; RO <= 0

LDR R1, R5, #0 ; load value of xLDR R2, R5, #-1 ; load value of yBRz DONE ; if y is zero, we're doneBRp LOOP ; if y is positive, start mult

; y is negativeNOT R1, R1ADD R1, R1, #1 ; R1 <= -x

NOT R2, R2ADD R2, R2, #1 ; R2 <= -y (-y is positive)

LOOP ADD R0, R0, R1 ; Multiply loopADD R2, R2, #-1 ; The result is in R2BRp LOOP

DONE STR R0, R5, #-2 ; z = x * Y


Recommended