Computer System Organization
Computer System Organization
Computer System Organization
Compilation of Lectures
Course Syllabus
Subject Code: CX323L1 Code: Descriptive Title: Computer System Organization Title: Credit Units: Lecture 3; Laboratory 1 Units: Pre-Requisite: Pre-Requisite: Logic Circuit and Switching Theory Course Description: This course covers: information in computers, covers: instruction sequencing and execution, addressing, instruction formats; formats; study of small computer systems and recent developments. developments.
Course Syllabus
General Objectives: At the end of the course, the students are expected to: Understand how the computer system works Provide a practical approach in assembly language programming Appreciate the importance of the assembly language in manipulating the computer hardware Gain basic knowledge in interfacing using assembly language
Course Syllabus
COURSE OUTLINE:
WEEK NUMBER TOPICS
PRELIM 1 2 3 4 5 6 Orientation Number System: Conversion and Operations Computer System Structure Introduction to Assembly Programming Debug Instruction Prelim Examination
Course Syllabus
MIDTERM 7 8 9 10 11 12 FINALS 13 14 15 16 17 18 Logic Instruction Introduction to Parallel Port Interfacing Status Port Port Control Project Presentation Final Examination
5
Introduction to Turbo Assembler String Manipulation Stack Instruction Control Instruction Screen Handling Instruction Midterm Examination
Number System
Number System Base/Radix Symbols
Bi
&
Decim l
-9
Hex decim l
-9; A-F
Conversion
I. Integral Part
A. Decimal to Binary 1. 2. 3. 4. Divide the decimal number by the radix of the desired number system List down the remainder Repeat steps 1 and 2 until the quotient becomes zero (0) Generate the final answer from the list of remainders from bottom to top
Conversion
EXAMPLES: Decimal to Binary 1. 4110 = 1010012 Quotient 41/2 20 20/2 10 10/2 5 5/2 2 2/2 1 1/2 0
Remainders 1 0 0 1 0 1
8
Conversion
2. 5310 = 1101012 Quotient 53/2 26 26/2 13 13/2 6 6/2 3 3/2 1 1/2 0 Remainders 1 0 1 0 1 1
Conversion
Decimal to Hexadecimal 1. 4110 = 2916 Quotient 41/16 2 2/16 0 2. 5310 = 3510 Quotient 53/16 3 3/16 0
Remainders 9 2
Remainders 5 3
10
Conversion
II. Fractional Part
1. Multiply the fraction by the base of the desired number system 2. List down the integral part 3. Repeat steps 1 and 2 until the integral part becomes zero (0) 4. Convert the final answer from the list of the integral part from top to bottom
11
Conversion
EXAMPLES: A. Decimal to Binary 1. 0.937510 = 0.11112 product .9375 *2 1.875 .875*2 1.75 .75*2 1.5 .5*2 1.0 2. 0.87510 = 0.1112 product .875*2 1.75 .75*2 1.5 .5*2 1.0
integral part 1 1 1 1
integral part 1 1 1
12
Conversion
B. Any Number System to Decimal 1. Multiply each digit of the given number by its increasing/ decreasing positional value 2. Add the products to get the final answer
EXAMPLES: Binary to Decimal 1. 101111.1012 = 47.625 1*2-3= 0.125 1*2-1= 0.5 1*20=1 1*21=2 1*22=4 1*23=8 1*25=32 47.625
13
Conversion
C. Binary To Hexadecimal 1. Partition the bits into groups of four from the binary point going from left to right 2. Assign the equivalent hex-digit for each group. hexEXAMPLE: Binary to Hexadecimal 1 B E . A 8 1. 1 1011 1110. 1010 12 = 1BE.A816 1 D E F . D C 2. 1 1101 1110 1111. 1101 112 = 1DEF.DC16
14
Conversion
D. Hexadecimal to Binary 1.Convert each digit of the given hexadecimal to it's binary equivalent.
EXAMPLE: Hexadecimal to Binary 1100 0000 1110. 1110 1110 1.C O E .E E 16 = 110000001110.111011102 1101 1110 1010 1111 . 1011 1110 1110 2.D E A F . B E E 16 = 1101111010101111.1011111011102
15
16
17
Complements
rs (radix complement) = 2's complement r-1s (diminished radix) = 1's complement 1's complement obtained by subtracting the bit from 1 (inverse) Example: 10101 = 01010 1's complement
18
Complements
2's complement obtained by taking the 1's complement then adding 1 to the least significant bit (LSB) of the complemented number Example: 10101 = 01010 1's complement + 1 01011 2's complement
19
20
Microcomputer Architecture
ADDRESS BUS
I PUT
MEMORY
EXECUTION UNIT
OUTPUT
DATA BUS
22
Pointer Registers
BP Register This 16 bit base pointer register facilitates referencing parameters, which are the data and the addresses that a program passes through the stack. stack. IP Register This 16 bit instruction pointer register contains the offset address of the next instruction that is to execute. It is associated execute. with the CS register in that the IP indicates the currents instruction within the currently executing code segment. segment. SP Register This 16 bit stack pointer register provides an offset value with out when associated with the SS register, refers to the current word being processed in the stack. Both the BP and SP registers stack. are associated with the SS register and permit the system to access data in the stack segment. segment.
24
Segment Registers
memory known as the current segment
- register that provide for addressing an area of
CS Register Code segment register contains the starting address of a program segment. This segment plus an offset value segment. in the IP register indicates the address of an instruction to be fetched for execution. execution. DS Register Data segment register contains the starting address of a programs data segment. Instruction use this address segment. to locate data. data.
25
Segment Registers
ES Register Extra segment register used by some string operations to handle memory addressing. Associated addressing. with DI register. register. Stack Segment (SS) Register Permits the implementation of a stack in memory that a program uses for temporary storage of addresses and data. The system stores the starting data. address of a programs stack segment in the SS register. register.
26
Index Registers
SI Register - 16 bit source index register is required for some string operations associated with the DS register. DI Register - 16 bit destination index register is also required for some string operations and is associated with the CS register.
27
Flag Registers
Special registers that indicate the present status of the computer of the results of processing. Many processing. instructions involving comparison and arithmetic change. change. The status of the flags which some instructions may test to determine subsequent action. action. 1. Overflow Flag (OF) Indicates that the result of an operation is too long to be stored in the destination operand.
OV of there is an overflow NV no overflow Ex. mov a1, 04 add a1, 7F int 20
28
Flag Registers
2. DF (Direction) Used in string operations to determine the direction of data transfer.
UP upward DN downward
3. Interrupt (IF) Indicates that all external interrupts such as keyboard entry are to be processed or ignored.
EI enabled DI disabled Ex. mov ah, 02 mov dl, 41 int 21 int 20
29
Flag Registers
4. SF (Sign) Indicates that the result of an operation is positive/negative
PL plus
Ex. mov al, 03 sub al, 08 int 20
NG negative
NZ non zero
30
Flag Registers
6. Auxiliary Carry (AF) Similar to carry flag except that it indicates the presence or absence of a carry or borrowed based on a 4 bit numeric representation in bits 0,1,2 and 3.
NA no auxiliary carry AC no auxiliary carry Ex. mov al, fl sub al, 01 int 20
7. Parity (PF) Indicates whether the result of an operation contains an even number or add number of 1s.
PE parity even PO parity odd
31
Flag Registers
Ex. mov al, 08 add al, 02 int 20
8. Carry Flag (CF) Indicates whether the instructions produced a value that can be too big or too small to be hold in the specified negative or memory location.
CY carry (N(Y) No no carry Ex. mov al, FF sub al, 01 int 20
32
6. INC (increment by 1) Used to increase the value of register by 1. Format: INC<register> Ex. INC AX INC CH
37
38
39
Debug Commands
1. Q (Quit) Finishes the debug session and exits back to dos environment. Ex. Q 2. H (Hexarithmetic) Shows the sum and different of two 4-digit 4hexadecimal number. Coded as H<hex value><hex value> Ex. H 000C 0008 3. R (Register) Allows you to display all registers and their values. Ex. R -R CX
40
Debug Commands
4. E (Enter) Enables you to key in data or machine instructions into memory beginning at a specific location address. Ex. E 0200 5. D (display or dump) Displays the contents of a portion memory in hex and ASCII forms starting with the given address Ex. D 0200 6. A (Assemble) Allows you to create program in mnemonic or symbolic code Ex. A 0100
41
Debug Commands
7. T (Trace) Runs the program in single step mode. It also displays the new values of the registers and the next instructions to be executed. Ex. T 8. G (Go) Runs the program as a whole in memory and displays the output Ex. G
42
Debug Commands
9. U (Unassemble) List all the instruction contained in the program beginning at the given address Ex. U 0100 -U 0100 0109 10. N (Name) Gives a name to a program the base name of the filename must be 8 characters long and the extension name is complete. Ex. N A :sample.com 11. W (Write) Solves the program onto disk stage. Ex. W
43
Language Translator
Language Translator
a language processor. a software that accepts source program added in high / mid language as input and produces the equivalent machine language.
45
2. Interpreter - processes the source program on a statement by statement basis. It translate high level language statements and then executes it one statement at a time. INTERPRETER high level INTERPRETER machine language
46
Linker
LINKER -a computer program for high, mid, low levels of programming language that completes the process by connecting the object code into executable machine code.
47
Assembly Language
ASSEMBLY LANGUAGE -a low level language that provides a kind of short hand notation called mnemonic (memory aid) for actual machine language instruction.
48
Categories
1. Instructions -statement that will be translated into machine language and executed by the computer. 2. Directives -statement that give information to the assembler not translated into machine language Example : .stack .model .data .code
50
Categories
3. Operators -use at assembly time to affect the value of an operand. Example: +, -, *, /
4. Predefined Symbols -symbols that return information to your program Example : data @model
5. Identifier -user defined name (variable) that you apply to an item in your program that you expect to references.
51
Types of Identifier
1. Name - refers to the address of data item 2. Label -refers to the address of an instruction or procedure.
52
53
Statement
a statement may begin anywhere in the program each line can only contain 1 statement not case sensitive a statement can have 2 operands, a single operand or none at all Example: add ax,bx dec cx ret
54
Directives
1.Title - creates a title up to 60 characters of a source 1.Title listing Example: Title this program displays 'kumusta' Title Prog1.asm 2. Model - specifies and initializes the memory model before defining any segment Example: .model tiny .model small .model medium
55
56
Sample Program
.model small ; initializes the memory model .stack ; .stack directives that directs the assembler to use stack .code ; .code directives that directs the assembler to use code begin ; label that denotes the body of the program mov ah,02h ; function that lets you print a character on a screen mov dl,' T ' ; assigns character ' T ' to register dl int 21h ; makes a function call mov dl, ' I int 21h mov dl, ' P ' int 21h mov ah,4ch ; program termination int 21h end begin ; ends the body of the program
57
Turbo Assembler
Turbo Assembler must contain the following : 1. Tasm.exe to assemble the program to create an object module Tlink.exe to create an executable program Edit workspace to create the source program Rtm.exe
2. 3. 4.
58
Function 09
function that displays a string of characters Example Program .model small .stack .data msg1 db TIP-Manila$ TIPmsg2 db1338 Arlegui St. Quiapo, Manila$ .code begin: mov ax, @data ; assigning data items in ax mov ds,ax ;data items should be in ds register
60
Function 09
mov ah,09h mov dx,offset msg1 ;loading the offset of ;the msg1 in the dx ;register int 21h mov ah,09h mov dx,offset msg2 int 21h mov ah,4ch int 21h end begin
61
Screen Location
Screen Location Upper Left Corner Upper Right Corner Center of the Screen Lower Left Corner Lower Right Corner Column Number 0 79 40 0 79 Row Number 0 0 12 24 24
62
Int 10h
use as a video function use to manipulate your output on the screen Example Program .model small .stack 0100h .code begin: mov ax,0600h ;ah=00h (full screen) mov bh,07h;0 (black background), 7 (white text color) mov cx,0000h ;ch=00h (row), cl=00h (column) mov dx,184Fh ;dh=18h (row), dl=4Fh (column) int 10h ;call interrupt service
63
Int 10h
mov ah,02h mov bh,00h mov dh,0ch mov dl,28h int 10h mov ah,02h mov dl,'x' int 21h mov ax,4c00h int 21h end begin ;request to set the cursor position ;page number (0) ;row=12 in decimal ;column=40 in decimal ;call interrupt service
64
Character Input
mov ah, 01h int 21h mov ah, 07h int 21h ;request for character input ;without echo ;request for character input ;with echo
65
Sample Program
;this program accepts any character typed from the keyboard .model small .stack .code begin: mov ah, 02h mov dh, 12 mov dl, 40 int 10h mov ah, 01h int 21h mov ah, 4ch int 21h end begin
66
67
68
Unconditional Jump
- JMP is considered unconditional jump instruction because it does not depend on a condition being true or false.
Format: Example: JMP <label> CMP AL, Y JE TAMA CMP AL, N JE MALI JMP TAPOS
TAMA: mov ah, 09h mov dx,offset msg1 int 21h TAPOS: mov ax, 4ch int 21hs
70
2 5
2 4
2 3
2 2
71
Types of Ports
Data Port output port (2-9) (2Status Port input port (10, 11, 12, 13, 15) Control Port I/O port (1, 14, 16, 17) (8-25 GND) (872
Port Addresses
Base
Data Port
Bit 0 1 2 3 4 6 7 6 7 8 9
74
Pin 2 3 4
turn off certain bits (set to 0) turn on certain bits (set to 1) complement certain bits (0 to 1, 1 to 0) complement all bits
75
76
77
78
Shift bits to the left and right respectively The bits that are shifted out are last The last bit to be shifted out is always kept in the carry flag cf; spaces are filled with 0s
79
Meaning
DL = 11001100
SHR DL, 3
DL = 00011001 CF = 1
SHL DL, 3
DL = 01100000 CF = 0
81
Basic Shift Instructions: SHL & SHR SAL = same as SHL SAR = duplicates the leftmost bit as you to the right Ex. SAR DL, 2 00001111 00000011 SAR BL, 2 11110001 11111100
82
shift
Rotate Instructions
With the shift instruction, bits are shifted out are last the empty spaces are filled with 0s (1s) With rotate instruction, bits from continuous loop as bit is shifted into the opposite side
83
Rotate Instructions
ROR = moves bits to the right Ex. ROR AL, 1 00001111
10000111
CF = 1
84
Rotate Instructions
RCR RCL = same as ROR ROL, CF is considered as an extra bit that participates in the rotation RCR AL, 1 AL CF 0011 1100 1
AL CF 10011110 0
CF 1
AL 11100000
85
Status Port
11 0
10 1
12 1
13 1
15 1
x 1
x 1
x 1
86