SlideShare ist ein Scribd-Unternehmen logo
1 von 279
CX323L1
COMPUTER SYSTEM
ORGANIZATION
COMPUTER SYSTEM
ORGANIZATION
Prelim Midterm Finals
Kaizen 2006 - 2007
TERMS
PRELIM
Week 1 – Microprocessor
Week 2 – Basic Structure of hardware and Softw
Week 3 – Register
Week 4 – System Operation
Week 5 - Editor
Microprocessors
Topics:
1.Microprocessor
2.History of Microprocessors
3.Types of Microprocessors
4.Number System
* Decimal
* Binary
* Octal
* Hexadecimal
Objectives
•To define what is a microprocessor.
• To discuss the history of microprocessor.
• Identify the types of microprocessor
• To recall numbers systems.
Microprocessors
The brain or engine of the PC is
the processor (sometimes
called microprocessor), or
central processing unit (CPU).
The CPU performs the system's
calculating and processing.
Brief History
• Intel is generally credited with creating the first microprocessor in
1971 with the introduction of a chip called the 4004.
• All PC-compatible systems use either Intel processors or Intel-
compatible processors from a handful of competitors
Example: AMD or Cyrix.
•Late 1970s the two most popular processors for PCs were not from Intel
(although one was a clone of an Intel processor). Personal computers of
that time primarily used the Z-80 by Zilog and the 6502 by MOS
Technologies.
• Z-80 was noted for being an improved and less expensive clone of the
Intel 8080 processor, similar to the way companies today such as AMD,
Cyrix, IDT, and Rise Technologies have cloned Intel's Pentium
processors.
Types of Microprocessor
Processors can broadly be divided into the categories of:
CISC, RISC, hybrid, and special purpose.
Complex Instruction Set Computers (CISC)
have a large instruction set, with hardware support for a
wide variety of operations. In scientific, engineering, and
mathematical operations with hand coded assembly
language (and some business applications with hand
coded assembly language), CISC processors usually
perform the most work in the shortest time.
Reduced Instruction Set Computers (RISC)
have a small, compact instruction set. In most business
applications and in programs created by compilers from
high level language source, RISC processors usually
perform the most work in the shortest time.
Hybrid
processors are some combination of CISC and RISC
approaches, attempting to balance the advantages of
each approach.
Special purpose
processors are optimized to perform specific functions.
Digital signal processors and various kinds of co-
processors are the most common kinds of special
purpose processors.
Function of Microprocessor
• To coordinate the functioning of the
various components of the system by
generating and responding to control
signals and to perform various arithmetic
and logic functions.
Number Systems
Decimal, Binary, Octal and
Hexadecimal Numeric Systems.
Conversions among the different
systems
Decimal Numbering systems
Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Example: 523410
103
= 1000 102
= 100 101
= 10 100
= 1
5 2 3 4
5,234 = 5 x 1000 + 2 x 100 + 3 x 10 + 4 x
1
Binary Numbering systems
• Base: 2
• Digits: 0, 1
• binary number: 1101012
positional powers of 2: 25
24
23
22
21
20
decimal positional value: 32 16 8 4 2 1
binary number: 1 1 0 1 0 1
Binary to Decimal
Conversion
• To convert to base 10, add all the values
where a one digit occurs.
Ex: 1101012
positional powers of 2: 25
24
23
22
21
20
decimal positional value: 32 16 8 4 2 1
binary number: 1 1 0 1 0 1
32 + 16 + 4 + 1 = 5310
Ex: 1010112
positional powers of 2: 25
24
23
22
21
20
decimal positional value:
binary number:
Ex: 1010112
positional powers of 2: 25
24
23
22
21
20
decimal positional value: 32 16 8 4
2 1
binary number: 1 0 1 0 1
1
32 + 8 + 2 + 1 = 4310
The Division Method. Divide by 2 until you reach zero,
and then collect the remainders in reverse.
Ex 1: 5610
= 1110002
2 ) 56 Rem:
2 ) 28 0
2 ) 14 0
2 ) 7 0
2 ) 3 1
2 ) 1 1
0 1
Ex 2: 3510
=
2 ) Rem:
2 )
2 )
2 )
2 )
2 )
Answer: 3510
= 2
Character Representation
Ex: Find the binary ASCII and decimal ASCII values for
the ‘&’ character.
Rightmost Leftmost Three Bits
Four Bits 000 001 010 011 100 101 110 111
0000 NUL DLE Space 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EOT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN && 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y I y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L  l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Character Representation
ASCII Table
From the chart:
‘&’ = 0100110 (binary ASCII value)
Convert the binary value to decimal:
01001102
= 32 + 4 + 2 = 3810
Therefore:
‘&’ = 38 (decimal ASCII value)
Octal Numbering systems
• Base: 8
• Digits: 0, 1, 2, 3, 4, 5, 6, 7
• Octal number: 12468
powers of : 84
83
82
81
80
decimal value: 4096 512 64 8 1
Octal number: 1 2 4 6
Octal to Decimal
Conversion
• To convert to base 10, beginning with the
rightmost digit multiply each nth digit by
8(n-1)
, and add all of the results together.
Ex: 12468
positional powers of 8: 83
82
81
80
decimal positional value: 512 64 8 1
Octal number: 1 2 4 6
512 + 128 + 32 + 6 = 67810
Ex: 103528
positional powers of 8: 84
83
82
81
80
decimal positional value:
Octal number:
The Division Method. Divide by 8 until you
reach zero, and then collect the remainders in
reverse.
Ex 1: 433010
= 103528
8 ) 4330 Rem:
8 ) 541 2
8 ) 67 5
8 ) 8 3
8 ) 1 0
0 1
Ex 2: 81010
=
8 ) 810 Rem:
8 )
8 )
8 )
Answer: 81010
= 8
Hexadecimal Numbering
systems
• Base: 16
• Digits: 0, 1, 2, 3, 4, 5, 6, 7,8,9,A,B,C,D,E,F
• Hexadecimal number: 1F416
powers of : 164
163
162
161
160
decimal value: 65536 4096 256 16 1
Hexadecimal number: 1 F 4
Four-bit Group Decimal Digit Hexadecimal Digit
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F
Hexa to Decimal Conversion
• To convert to base 10, beginning with the
rightmost digit multiply each nth digit by
16(n-1)
, and add all of the results together.
Ex: 1F416
positional powers of 16: 163
162
161
160
decimal positional value: 4096 256 16 1
Hexadecimal number: 1 F 4
256 + 240 + 4 = 50010
Ex: 7E16
positional powers of 16: 163
162
161
160
decimal positional value:
Hexa number:
• The Division Method. Divide by 16 until
you reach zero, and then collect the
remainders in reverse.
Ex 1: 12610
= 7E16
16) 126 Rem:
16) 7 14=E
0 7
Ex 2: 81010 =
16 ) 810 Rem:
16 )
16 )
Answer: 81010
= 16
Binary to Octal Conversion
• Since the maximum value represented in 3 bit is equal
to:
23
– 1 = 7
• i.e. using 3 bits we can represent values from 0 –7
which are the digits of the Octal numbering system.
• Thus, three binary digits can be converted to one
octal digit and visa versa.
Three-bit Group Decimal Digit Octal Digit
000 0 0
001 1 1
010 2 2
011 3 3
100 4 4
101 5 5
110 6 6
111 7 7
Ex :
Convert 7428 = 2
7 = 111
4 = 100
2 = 010
7428 = 111 100 0102
Ex :
Convert 101001102 = 8
110 = 6
100 = 4
010 = 2 ( pad empty digits with 0)
101001102 = 2468
Four-bit Group Decimal Digit Hexadecimal Digit
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F
Ex :
Convert 3D916 = 2
3 = 0011
D = 1101
9 = 1001
3D916 = 0011 1101 10012
Ex :
Convert 101001102 = 16
0110 = 6
1010 = A
101001102 = A616
To convert between Octal to Hexadecimal
numbering systems and visa versa convert
from one system to binary first then convert
from binary to the new numbering system
Ex :
Convert E8A16 = 8
1110 1000 10102
111 010 001 010 (group by 3
bits)
7 2 1 2
E8A16 = 72178
Ex :
Convert 7528 = 16
111 101 0102 (group by 4 bits)
0001 1110 1010
1 E A
7528 = 1EA16
Ex :
Convert 7528 = 16
111 101 0102 (group by 4 bits)
0001 1110 1010
1 E A
7528 = 1EA16
Basic Structure of hardware and
Software
Topics:
• Internal Hardware Features
• External Hardware Features
• Program Organization
• Memory Organization
• Basics of Assembly Programming
• SK Editor
• Using Debug
Objectives
• To familiarize with the basic structure of
hardware and software
• To discuss programming model and
memory organization
• To discuss assembly programming using
debug.
Basic Structure of Hardware
and Software
Hardware – is the physical part of the
computer system
Software - A program or set of instructions
that controls the operation of a computer.
Distinguished from the actual hardware of the
computer.
Internal Hardware Features
1. Processor
2. Memory
3. Registers
External Hardware Features
Computer’s Input/Output
example:
1. Keyboard
2. Monitor
3. Disk
4. CD-ROM
Program Organization
• Software consists of the operating system and
various programs and data files stored on disk.
• To execute (or run) a program:
1. the system copies it from external device
into internal memory.
2. the processor executes the program
instructions.
3. The registers handle the requested
arithmetic, data movement, and addressing.
Memory Organization
Bit – the fundamental building block of
computer storage
- off means 0, on means 1
Bytes – consists of eight bits for data and one
bit for parity
0 0 0 0 0 0 0 0 1
Data bits parity
According to the rule of parity, the number of bits
that are on in each byte must always be odd.
Related Bytes
• A program can treat a group of one or
more related bytes as a unit of data, such
as time or distance. A group of bytes that
defines a particular value is commonly
known as a data item or field.
• Word – a 2-byte (16-bit) data item
• Doubleword – A 4-byte (32-bit) data item
• Quadword – An 8-byte (64-bit) data item
• Paragraph – a 16-byte (128 bit) area
• Kilobyte (KB) – The number 210
equals,
1,024, which happens to be the value K,
for kilobyte.
• Megabyte (MB) – The number 220
equals
1,048,576, or 1 megabyte.
Basics of Assembly
Programming
Programming Language
A programming language is a notation for
expressing instructions to be carried out
by the computer. It is a medium of
communication between the human and
the machine, and often between one
human being and another.
Classification of programming
Languages
• High-Level Language – A high-level language is an English-like
language that provides for more natural expression of
algorithms.
Examples: BASIC, Pascal, COBOL, & Prolog
• Mid-level Language– It is a computer language which combines
low-level efficiency with high-level language structure,
abstraction and portability.
Examples: C & MODULO-2
• Low-level Language – A low-level language is considered to be
machine-oriented since it is closely follows the built in
instruction set of the underlying computer.
Examples: Assembly, machine languages.
Assembly Language
• It is a low-level language that provides a
kind of shorthand notation called
mnemonic (memory aid) for the actual
machine language instruction. It is a
much easier to remember SUB AX<BX
than 0010101111000011 which is the
actual instruction code that the machine
uses.
SideKick Editor
• It is a text editor used in coding the source
code. SideKick or SK editor can display
the ASCII code for coding assembly
language program.
Debug
• BUG - It is a computer terminology for error or
mistake in a program or computer system and
the term debugging is a methodical process of
finding and reducing the number of bugs or
defects in a computer program.
• DEBUGGER – It is a program tool that provides
an environment for testing load modules. Load
modules are executable programs
Registers
Topics:
1. Register
2. General Purpose Registers
3. Pointer Registers
4. Segment Registers
5. Index Registers
6. Flag Registers
Objectives
1. To define what is a register.
2. Identify the types of registers.
3. Identify the function of each register.
Register Set
Registers are fast memory, almost
always connected to circuitry that allows
various arithmetic, logical, control, and
other manipulations, as well as possibly
setting internal flags.
General-Purpose Registers
AX - Accumulator Register mostly used for
calculations and for input/output
BX - Base Register Only register that can be used
as an index
AH AL
AX
EAX
BH BL
BX
EBX
• CX - Count Register used for the loop
instruction
• DX - Data Register input/output and used
by multiply and divide
CH CL
CX
ECX
DH DL
DX
EDX
Pointer Registers
IP - Instruction Pointer 16-bit number that
points to the offset of the next instruction
SP - Stack Pointer 16-bit number that points
to the offset that the stack is using
BP - Base Pointer used to pass data to and
from the stack
Segment Registers
CS - Code Segment 16-bit number that
points to the active code-segment
DS - Data Segment 16-bit number that points
to the active data-segment
SS - Stack Segment 16-bit number that
points to the active stack-segment
ES - Extra Segment 16-bit number that
points to the active extra-segment
Index Registers
SI - Source Index used by string operations as
source
DI - Destination Index used by string
operations as destination
Flag Registers
Abr. Name bit nº Description
OF Overflow
Flag
11 indicates an overflow when set
DF Direction
Flag
10 used for string operations to check direction
IF Interrupt
Flag
9 if set, interrupt are enabled, else disabled
TF Trap Flag 8 if set, CPU can work in single step mode
SF Sign Flag 7 if set, resulting number of calculation is negative
ZF Zero Flag 6 if set, resulting number of calculation is zero
AF Auxiliary
Carry
4 some sort of second carry flag
PF Parity Flag 2 indicates even or odd parity
CF Carry Flag 0 contains the left-most bit after calculations
System Operation
Topics:
• Disk Operating System
• Debug
• Loading of Debug from DOS
• Loading SK through DOS
Objectives
• To recall common DOS commands.
• To discuss the procedures in starting and
quitting Debug.
• To familiarize with the Debug commands.
• To know the rules in using debug
commands.
System Operation
Common Disk Operating System Commands
1. CLS - clear 5. DEL - delete
2. CD – change dir 6. REN - rename
3. DIR - directory 7. MD – make directory
4. COPY - copy 8. RD – remove directory
DEBUG
Debug – is a software that is classified as
debugger which is used for testing and
debugging executable programs.
- It displays all program code and data in
hexadecimal format and any data that you
enter into memory must also in hex form.
Advantages of Debug
1. It is free.
2. It is universally available.
3. It is simple to use.
4. It requires relatively little
memory.
Debug Commands
1. Q (Quit)
Finishes the Debug session and exits back to
DOS environment
Ex: -Q
2. H (Hexarithmetic)
Shows the sum and difference of two 4-bit
hexadecimal numbers, coded as H <hex
value> <hex value>
Ex: - 000C 0008
3. R (Register)
Allows you to display all registers and their
values. It also shows the next instruction
and permits you to change the value of a
particular register.
Ex: -R
-R CX
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 content 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. It also translates this
assembly source statements that you
create into machine code.
Ex: -A 0100
7. T (Trace)
Runs the program in a 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
9. U (Unassemble)
Lists all the instructions contained in the program
beginning at the given address. You can also
specify the last address location.
Ex: -U 0100
-U 0100 0109
10.N (Name)
Gives a name to your program, coded as N
<path><filename>. The base name of the
filename must be eight characters long and
the extension name is .COM
Ex: N A:SAMPLE>COM
11.W (Write)
Saves the program onto the disk storage.
Ex: -W
Rules of Debug Commands
•It is not case sensitive
•It assumes that all numbers given are in
hexadecimal format.
•You can enter a space only when it is
needed to separate parameters of a
particular command.
•You should specify segments and
offsets with a colon, in the form
<segment>:<offset>.
Starting Debug
1. Key in the word debug and
press enter. A hyphen (-)
appears on the screen, that is
the DEBUG prompt. DEBUG
is now ready to accept
commands.
C:>debug
-
Quitting and Closing Debug
To close Debug and go back to
DOS environment: type Q and
press ENTER key.
C:>debug
-q
C:>
Loading SK Through DOS
• From the C:> prompt type SK then the
SideKick main menu will appear. From
the menu select Notepad or press F2.
C:>sk
Basic Assembly Instructions Used in
Debug
1. MOV (Move data)
It copies and transfers data between two
registers, or between an immediate data to a
register.
Format: MOV <register>,<register>
MOV <register>, <immediate data>
Example: MOV AX,BX
MOV CX, 5083
MOV CL,DL
MOV BL,33
2. ADD (Add Data)
It is used to get the sum of two registers or a
register and an immediate data, and
stores the result to the left most register.
Format: ADD <register>,<register>
ADD <register>,<immediate data>
Example: ADD CX,BX
ADD AX,0308
ADD AL,BL
ADD DH, 95
3. SUB (Subtract Data)
It is used to get the difference of two registers or
a register and an immediate data, and stores
the result to the left most register.
Format: SUB <register>,<register>
SUB <register>,<immediate data>
Example: SUB CX,BX
SUB AX,0308
SUB AL,BL
SUB CL,95
3. MUL (Multiply Data)
It is used to get the product of the given register
and AX register, and stores the result to AX
register. If the product is greater than 16 bits,
the overflow is stored in DX register.
Format: MUL <register>
Example: MUL CX
5. DIV (Divide Data)
It is used to divide the value of a given register
and AX register, and stores the quotient to AX
and the remainder to DX registers
respectively.
Format: DIV <register>
Example: DIV BX
6. INC (Increment by one)
It is used to increase the value of the register by
one (1).
Format: INC <register>
Example: INC AX
INC CH
7. DEC (Decrement by one)
The opposite of INC, instead of increasing, it
decreases the value of the register by one
(1)
Format: DEC <register>
Example: DEC AX
DEC CH
8. LOOP (Loop Until Complete)
It controls the execution of a program segment in
a specified number of times. The CX register
should contain a count value before starting
the loop and automatically decrements by one
(1). If CX is not equal to zero (0), it transfers
to its operand address which points to the
start of the loop; otherwise it drops through to
the next instruction.
Format: LOOP <offset address>
Example: LOOP 0108
Sample Debug Programs
Displaying a smiley character on the screen.
-A 0100
1358:0100 mov ah,02 ;request display character
1358:0102 mov dl,01 ;character to display
1358:0104 int 21 ;call interrupt service
1358:0106 int 20 ;end
13587:008
-G
Program terminated normally
-
Using control characters (0A – Line Feed and 0D – Carriage Return) in
a screen display.
-A 0100
1358:0100 MOV AH, 02 ;request display character
1358:0102 MOV DL,54 ;character ‘T’
1358:0104 INT 21 ;call interrupt service
1358:0106 MOV DL, 0A ;line feed character
1358:0108 INT 21 ;call interrupt service
1358:010A MOV DL,0D ;carriage return character
1358:010C INT 21 ;call interrupt service
1358:010E MOV DL,49 ;character ‘I’
1358:0110 INT 21 ;call interrupt service
1358:0112 MOV DL,0A ;line feed character
1358:0114 INT 21 ;call interrupt service
1358:0106 MOV DL,0D ;carriage return character
1358:0118 INT 21 ;call interrupt service
1358:011A MOV DL,50 ;character ‘P’
1358:011C INT 21 ;call interrupt service
1358:011E INT 20 ;end
Displaying the same character (lowercase ‘z’) thirty times using
loop on the screen.
-A 0100
1358:0100 MOV CX,001E ;SETTING THE NUMBER OF LOOOPS
1358:0103 MOV AH,2 ;REQUEST DISPLAY CHARACTER
1358:0105 MOV DL,7A ;CHARCTER TO DISPLAY
1358:0107 INT 21 ;CALL INTERRUPT SERVICE
1358:0109 LOOP 0107 ;GO TO OFFSET 0107
1358:010B INT 20 ;END
Editor
Topics:
1. Editor
2. Types of language translator
3. Advantages of assembly language
Objectives
• To identify the different editors used in
assembly language.
• Differentiate the different types of
language translator.
• Enumerate the advantages of assembly
language.
Editor
Text Editors used in Turbo Assembler
1. Edit
2. Sidekick
3. Pilot
Turbo Assembler
Types of language
Translator
1. Compiler – Is a translator program that
transforms an entire source program
composed of high/mid-level language
statements into an object program
consisting of machine language
executable code.
High/Mid-level language
Source Program COMPILER
Machine language
Instruction
2. Interpreter – processes the source program on a
statement-by-statement basis. It translates
high/mid-level language statements and then
executes it one statement at a time.
2. Assembler – is a language translator that
transforms assembly language to machine
language instruction.
High/Mid-level language
Source Program INTERPRETER
Machine language
Instruction
Assembly language
Source Program ASSEMBLER
Machine language
Instruction
Assembly Language
It is a low-level language that provides a kind
of shorthand notation called
mnemonic(memory aid) for the actual
machine language instruction. It is much
easier to remember SUB, AX, BX than
00101111000011 which is the actual
instruction code that machine uses…
Advantages of Assembly
language
•It provides more control over
handling particular hardware
requirements.
• It generates smaller, more
compact executable modules.
• It results in faster execution.
Tasm – Turbo Assembler
T-link t - Turbo Assembler Linker
Linker is a computer program for high, mid, and
low levels of programming language that
completes the process by converting the object
code into executable machine code.
STRUCTURE OF AN ASSEMBLY
LANGUAGE PROGRAM
TITLE MYPROG.ASM
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
X DB “Hello everyone! $”
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
MOV DX, OFFSET X
MOV AX, 4C00h
INT 21h
END
INSTRUCTIONS FOR
INITIALIZING THE PROGRAM
TITLE MYPROG.ASM
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX, @DATA
MOV DS, AX
INSTRUCTIONS FOR
CONCLUDING THE PROGRAM
MOV AX, 4C00h
INT 21h
END
EXAMPLES OF ASSEMBLY LANGUAGE
PROGRAMS
• Displaying a character (uppercase ‘A’) on screen.
TITLE MYPROG.ASM ; name of the program
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h ; request display
character
MOV DL, ‘A’ ; character to display
MOV AX, 4C00h ; end
INT 21h
END
Displaying character (lowercase ‘b’) twice on screen.
TITLE MYPROG.ASM ; name of the program
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h ; request display character
MOV DL, ‘b’ ; character to display
INT 21h ; call interrupt service
INT 21h ; call interrupt service
MOV AX, 4C00h ; end
INT 21h
END
• Using control characters (0A – Line Feed and 0D – Carriage return) in a screen display.
TITLE MYPROG.ASM ; name of the program
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h ; request display character
MOV DL, ‘T’ ; character to display
INT 21h ; call interrupt service
MOV DL, 0Ah ; line feed character
INT 21h ; call interrupt service
MOV DL, 0DH ; carriage return character
INT 21h ; call interrupt service
MOV DL, ‘I’ ; character ‘I’
INT 21h ; call interrupt service
MOV DL, 0Ah ; line feed character
INT 21h ; call interrupt service
MOV DL, 0Dh ;carriage return character
INT 21h ; call interrupt service
MOV DL, ‘P’ ; character ‘P’
INT 21h ; call interrupt service
MOV AX, 4C00h ; end
INT 21h
END
• Displaying different characters (‘A to ‘Z’) using LOOP on the
same line.
TITLE MYPROG.ASM
DOSSEG
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX,@DATA
MOV DS,AX
MOV CX,001Ah ; setting the number of loops
MOV AH,02h ; request display character
MOV DL,‘A’ ; character ‘A’
B: INT 21h ; call interrupt service
INC DL ; add to 1 to the value of DL
LOOP B ; go to label B
MOV AX,4C00h ; end
INT 21h
END
MIDTERM
Week 7- Instructions And Directives
Week 8 – Introduction to Assembly Language
Week 9 – Using SK Editor
Week 10 – Keyboard handling
Week 11 – Screen Handling
Instructions And Directives
Topics:
• Instructions
• Categories of Instructions
• Directives
• Types of Memory Model
Objectives
To familiarize with the different instructions.
To identify the categories of instructions
To identify the different directives and their
corresponding functions.
To identify the different memory modes.
Instructions
- These are statements that will
be translated into machine
language and executed by the
computer.
Examples of instructions
MOV ADD SUB
MUL DIV INC
DEC LOOP CMP
Categories of Instructions
1. DATA TRANSFER
To move data in the memory and in the
CPU registers.
Format:
Memory to register
Register to register
Register to stack
Stack to register
Syntax: Mov Destiny, Source
Example: mov ax,bx
Note: the list of symbolic instructions are for Intel processor
family
There are two very important
details to note about the mov
instruction
1. There is no memory to memory move
operation.
2. You cannot move immediate data into a
segment register.
LDS: Load Data Segment Register
LEA: Load Effective Address
LES Load Extra Segment Register
LODS: Load String
LSS: Load stack Segment Register
MOV: Move data
MOVS: Move String
MOVSX: Move with sign-extend
MOVZX: Move with Zero-extend
STOS: Store string
XCHG: Exchange
XLAT: Translate
2. ARITHMETIC
Syntax: Adc destiny, source
Example: Adc bh,bl
ADD: add binary numbers ADC: Add with carry
DEC: Decrement by 1 INC: Increment by 1
DIV: Unsigned Divide IDIV: Signed (integer) divide
MUL: Unsigned multiply IMUL: Signed multiply
SUB: Subtract binary values SBB: Subtract with borrow
XADD: exchange and add
3. COMPARISON
Syntax: CMP destiny, source
Example: cmp ax,bx
CMP: compare
CMPSn: Compare string
CMPXCHG: Compare and exchange
4. LOGICAL OPERATIONS
Syntax: AND destiny,source
Example: And ax,bx
AND: Logical AND
NOT: Logical NOT
OR: Logical OR
XOR: Exclusive XOR
5. INPUT/OUTPUT
Syntax: OUT destiny,source
Example: in ax,dx
IN: Input byte or word
INSn: Input string
OUT: Output byte or word
OUTSn: Output string
6. JUMP(conditional)
Syntax: ja label
Example: ja start
JA: Jump if Above
JAE: Jump if above/equal
JB: Jump if below
JBE: Jump if below/equal
JE: Jump if Equal
JG: Jump if Greater
JGE: Jump if Greater/Equal
JL: Jump if Less
JNE: Jump if Not Equal
JNG: Jump if Not Greater
JNGE: Jump if Not Greater/Equal
JNL: Jump if Not Less
JNLE: Jump if Not Less/Equal
JNZ: Jump if Not Zero
JLE: Jump if Less/Equal
JNA: Jump if Not Above
JNB: Jump if Not Below
JNBE: Jump if Not Below/Equal
JZ: Jump if Zero
JC: Jump if Carry
JCXZ: Jump if CX is Zero
JNO: Jump if No Overflow
JO: Jump if Overflow
JNP: Jump if No Parity
JP/JPO: Jump if Parity Odd
JPE: Jump if Parity Even
JS: Jump if Sign
JNS: Jump if No Sign
7. JUMP (Unconditional)
CALL: Call a procedure
INT: Interrupt
IRET: Interrupt Return
JMP: Unconditional Jump
RET: Return
RETN/RETF: Return Near/Return Far
8. LOOPING
Syntax: loop label
Example: loop a
LOOP: Loop until complete
LOOPE: Loop While Equal
LOOPZ: Loop While Zero
LOOPNE: Loop While Not Equal
LOOPNZ: Loop While Not Zero
9. STACK INSTRUCTIONS
Syntax: pop destiny
Example: pop ax
POP: Retrieve the content of the Stack
PUSH: Store the content of the Stack
POPF: Pop Flags off the Stack
PUSHF: Push Flags onto Stack
Directives
- These are statements that give information to
the assembler.
- Sometimes called pseudo-ops (short term for
pseudo operations and pronounced as”su-da-
op”).
- Unlike instructions, directives are not
translated is not machine language but they are
necessary for your program to assemble
properly.
Examples of Directives
TITLE DOSSEG .MODEL
.STACK .DATA .CODE
Most Common Directives
1. TITLE – It creates a title (up to 60
characters) of a source listing.
Format:
Example: TITLE PROGRAM1.ASM
TITLE <TEXT>
2. DOSSEG – It tells the
assembler to ignore all other
requests and to adopt the
DOS segment sequence –
stack, data and code.
Format:
Example: DOSSEG
DOSSEG
3. .MODEL – It specifies and initializes the memory
model before defining any segment.
Format:
Example: .MODEL TINY
.MODEL SMALL
.MODEL MEDIUM
.MODEL SMALL <MEMORY-MODEL>
Types of Memory Model
MEMORY MODEL NO. OF DATA SEGMENT NO. OF CODE SEGMENT
Tiny 0 0
Small 1 1
Medium 1 More than 1
Compact More than 1 1
Large More than 1 More than 1
4. .STACK – It defines the size of the stack.
The default size is 1,024 bytes which you
can overrule.
Format:
Example: .STACK 0100h
.STACK <SIZE>
5. .DATA – It defines and marks
the beginning of data segment.
Format:
Example: .DATA
.DATA
6. .CODE – It defines and marks
the code segment which
consists of a set of
instructions.
Format:
Example: .CODE
.CODE
7. END – It is placed at the last
line of the source code.
Format:
Example: END
END
8. For Defining Data
DIRECTIVE LENGTH DESCRIPTION
DB 1 Define Byte
DW 2 Define Word
DD 4 Define Doubleword
DF 6 Define Farword
DQ 8 Define Quadword
DT 10 Define Tenbytes
Introduction to Assembly
Language
Topics:
• Requirements for Coding Assembly language
• Reserved Words
• Identifiers
Objectives
• To know the requirements in coding
assembly language
• To identify the different reserved words.
• To know the categories of reserved words
• To identify the two types of identifiers.
• To know the general guidelines in coding
assembly program.
Introduction to Assembly
Language Using Turbo
Assembler
Requirements for Coding
Assembly language
Comment
-Is a part of a program that is ignored by the
assembler. Though Optional, the use of
comments throughout a program can improve
its readability and clarity especially in
assembly language where the purpose of a
set of instructions is often ambiguous.
-It begins with a semicolon(;)
Ways to include comment
• Any Statement whose first non-blank character is a
semicolon.
Example: ; This program displays Good Day!
•At the end of an instruction.
Example:
MOV AX, 8053h ; initializes the value of ax to 8053h
Reserved Words
These are words in which the assembler
assigns a special meaning and it cannot
be used as identifiers. They are reserved
for their own purpose to be used only
under special condition.
Categories of Reserved Words
•Instructions
•Directives
•Operators
•Pre-defined Symbols
Identifiers
An identifier is a user-defined
name (Variable) that you apply to
an item in your program that you
expect to reference.
Types of Identifiers
•Name – It refers to the address of a data item.
Example: x db 0
msg db “Aloha! &”
•Label – It refers to the address of an instruction or
procedure.
Example: mov dl, 41h
A: int 21h
add dl, 20h
int 21h
sub dl, 20h
loop A
Rules in Constructing Valid Identifier
•It must be letters (A..Z, a..z), numbers (0-9)
&/or special characters like underscore(_),
question mark(?) and at sign (@).
•* It must always start with a letter.
•It must not use reserved words.
•It must not exceed to 31 characters.
Examples of valid identifiers: neym u2u2
num_1 msg8
Examples of Invalid identifiers: title num-1
4ever F-4
Statement
An assembly language statement program
consists of a set of statements. The two
types of statements are instructions and
directives.
General Guidelines for coding statement
•A statement may begin anywhere on the line
•Each line can only contain one statement
•Unlike C language, assembly is not case
sensitive. You can use either upper or
lowercase letters.
•Take note that statements can have two (2)
operands, a single and even none at all.
Examples: ADD AX,BX ;uses 2 operands
DEC CX ; uses single operand
RET ; no operand
String
-is used for directive data such as person’s
name or simply a message. It must end with
dollar ($) symbol and defined in double
quotation marks (“ ”). DB is the conventional
format for defining string of any length.
Example:
Neym db “Mary’s Internet Café $”
Numeric Constant
-They are used to define arithmetic values and
memory addresses. It is identified with a radix
specifier such as d for decimal, b for binary
and h for hexadecimal.
Example:
Msg db “Good day!”, 0ah, 0dh, “$”
Is the same with
Msg db “Good day!”, 10d, 13d “$”
Msg db “Good day!”, 00001010b, 00001101b, “$”
Using SideKick
Assembling and Linking
Procedures
Topics:
• Using SideKick
• Creating Assembly Language
• Structure of Assembly language
• Assembling and Linking Assembly Language
Objectives
• To familiarize with the SideKick
Environment as text editor.
• To know the procedures in invoking
Sidekick and quitting from the SideKick
window.
• To know the procedures in creating and
saving assembly program.
• To know the procedures in assembling,
linking and running assembly program.
Using Sidekick as Editor
Sidekick
- is an editor used for DOS
programming like assembly
language.
Creating Assembly Language
Program
Step 1: Open the text editor.
C:tasm>SK
Step2: Type the name of the
program with .asm as file
extension name.
Example: c:program1.asm
Step3: You may now start typing
your source code.
Exiting from the Sidekick
Window
* Press escape (esc )key to go
back to DOS environment.
Structure of an Assembly Language Program
TITLE PROGRAM1.ASM
DOSSEG
.MODEL SMALL
.STACK
.DATA
X DB “HELLO THERE!$”
.CODE
MOV AX, @DATA
MOV DS,AX
MOV AH,O9H
MOV DX,OFFSET X
INT 21H
MOV AX,4C00H
INT 21H
END
Initializes the program
Concludes the program
Body of the program
Assembling and Linking
Procedures
Assembling:
From the c:tasm> prompt type the following the
filename and its extension name then press enter
key.
Example: c:tasm>program1.asm
Linking:
After a successful assembly (I.e., no errors
encountered), type tlink, press space bar,
filename and its extension name then
press enter key
Example: c:tasm>tlink program1.obj
Executing:
To run the program, just type the filename
only at c:tasm>.
Example: c:tasm>program1
To recapitulate the overall process:
1. Open the text editor.
2. Save the program.
3. Start keying your program.
4. Exit the editor and go back to DOS environment by
pressing the Esc key.
5. Assemble the program by typing tasm
filename.asm.
6. If there are no errors, do the next step otherwise,
repeat steps 1-5 and rectify the program.
7. Link the object file by typing tlink filename.obj &
press enter key.
8. Type filename and press enter key to run the
program.
KEYBOARD HANDLING
Topics:
Interrupt and Service
Character Output
Character Input
String Display
String Input
Objectives
• To identify the function/service number
used to input/output character.
• To identify the function/service number
used to input/output string.
• To identify the corresponding interrupt
used in character and string input/output.
Interrupt – execute commands
Service – set the command
Interrupt and Service
Character Output
Int 21h / 02
This function display one character on the
screen.
AH = 02h
DL = holds the character to display on the
screen.
Example:
. MODEL SMALL
. STACK 0100h
. DATA
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h ; request display character
MOV DL, ‘j’ ; character to display
INT 21h ; call interrupt service
INT 21h ; call interrupt service
MOV AX, 4C00h ; end
INT 21h
END
Character Input
Int 21h / 1 – Keyboard input
This function waits for you to
type a character on the keyboard. It
echoes the character to the screen and
returns the ASCII character in the AL
register.
AH = 01
AL = character read from the keyboard
Example:
.model small
.stack
.data
.code
mov ah, 01h ; request for character input
int 21h
Character Input
Int 21h / 7 – keyboard input without echo
This function reads a character
from a keyboard but doesn’t display the
character on the screen and wait for
control break.
AL = character read from the keyboard
Character Input
Int 21h / 8 – keyboard input without echo
This function works the same
way with service 7 but do not respond to
control break.
AL = character read from the keyboard
Example:.MODEL SMALL
.STACK 0100H
.DATA
MSG DB “INPUT ANY CHARACTER: $”
MSG2 DB 0AH, 0DH, “The character you type is: $”
x db 0
.CODE
MOV AX,@DATA
MOV DS, AX
MOV AH,09H
MOV DX,OFFSET MSG1
INT 21H
MOV AH,01H ;REQUEST FOR CHARACTER INPUT
INT 21H
MOV X,AL
MOV AH,09H
MOV DX,OFFSET MSG2
INT 21H
MOV AH,02H
MOV DL,X
INT 21H
MOV AX,4C00H
INT 21H
String Display
Int 21h / 09
This function displays the string pointed by
the DS:DX pair of registers. The end of
the string should be marked with the $
sign.
DS:DX points to address of the string
String Display
Int 21h / 09h
Display string in the data area followed by a
dollar sign ($ or 24h) delimiter, which the
operation uses to end the display.
Example:
Nick_name db “Your nickname: $“ ;display string
Example fragment of a program
MOV AH,09H ;request display
LEA DX, NICK_NAME ;load address of prompt
INT 21H ;call interrupt service
String Input
Int 21h / 0A
This function reads the string from the
keyboard.
DS:DX points to address of the string
Example:
. MODEL SMALL
. STACK 0100h
. DATA
NEYM DB 08h, ?, 08h DUP (“$”)
Q DB “What is your name? $”
A1 DB 0Ah, 0Dh, “What a nice name ! $”
A2 db 0Ah, 0Dh, “I’m glad to meet you ! $”
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
MOV DX, OFFSET Q
MOV AH, 0Ah ; request for string input
MOV DX, OFFSET NEYM ; load address
INT 21h
MOV AH, 09h
MOV DX, OFFSET A1
INT 21h
MOV AH, 09h
MOV DX, OFFSET NEYM+2
INT 21h
MOV DX, OFFSET A2
INT 21h
MOV AX, 4C00h
INT 21h
END
DISPLAYING THE INPUT STRING
The following instructions display the input string
starting at the third memory address.
MOV AH, 09h ; request for string output
MOV DX, OFFSET X+2 ; LOAD ADDRESS
INT 21h
Sample program that demonstrates
string and displays it again on screen.
. MODEL SMALL
. STACK 0100h
. DATA
NEYM DB 08h, ?, 08h DUP (“$”)
Q DB “What is your name? $”
A1 DB 0Ah, 0Dh, “What a nice name ! $”
A2 db 0Ah, 0Dh, “I’m glad to meet you ! $”
. CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
MOV DX, OFFSET Q
MOV AH, 0Ah ; request for string input
MOV DX, OFFSET NEYM ; load address
INT 21h
MOV AH, 09h
MOV DX, OFFSET A1
INT 21h
MOV AH, 09h
MOV DX, OFFSET NEYM+2
INT 21h
MOV DX, OFFSET A2
INT 21h
MOV AX, 4C00h
INT 21h
END
Screen Handling
Topics:
• The Monitor
• GRAPHICS
Objectives
• To identify the instructions and directives
used for screen handling applications
• To create an assembly program with the
application of graphics.
THE MONITOR
• A typical video screen has eighty (80)
columns numbered from 0 to 79 and
twenty five (25) rows numbered from o to
24. The columns and rows provide a grid
of addressable locations at any one of
which the cursor can be set. The table
below shows the examples of a cursor
locations
Screen
Location
COLUMN ROW COLUMN ROW
In hexadecimal value In hexadecimal value
Upper Left
Corner
0 0 00H 00H
Upper Right
Corner
79 0 4FH 00H
Center of
Screen
40 12 28H 0CH
Lower Left
Corner
0 24 00H 18H
Lower Right
Corner
79 24 4FH 18H
Screen Features
Clearing the Screen in Assembly
Approach
Int 10h / 06h
Handles the process of clearing the
screen and scrolling.
AH = Function in 06H
AL = number of lines to scroll, or 00H for the full screen
BH = attribute value (color blinking etc.)
CX = starting row column
DX = ending row column
sample code shows how to create the
clear screen:
MOV AX,0600h ;AH=06h (Scroll), AL=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
SETTING THE CURSOR
POSITION
Int 10h / 02
Used to set the cursor position.
AH = 02
MOV AH, 02h ; request to set the cursor position
MOV BH, 002h ; page number 0
MOV DH, 0Ah ; Row = 10 in decimal
MOV DL, 08h ; Column = 8 in decimal
INT 10h ; call interrupt service
Alphanumeric
DISPLAYING THE STRING ‘FLOWERS’ AT THE CENTER OF THE SCREEN
.MODEL SMALL
.STACK 0100h
.DATA
A DB “FLOWERS$”
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,0600h ; AH=00h (Scroll0, AL=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
MOV AH,02h ; request to set the cursor position
MOV BH,00h ; page number 0
MOV DH,0Ch ; Row = 12 in decimal
MOV DL,24h ; Column = 36 in decimal
INT 10h ; Call interrupt service
MOV AH,09H ; request display string
LEA DX,A ; load address of the string
MOV AX, 4C00h
INT 21h
END
Graphics
TEXT AND BACKGROUND COLORS
BACKGROUND COLOR TEXT COLOR HEX CODE MEANING
BL R G B I R G B
0 0 1 0 1 0 0 0 28 Green Background Color
Gray Text Color
1 0 1 0 1 0 0 0 0A8 Green Background Color
Gray Black Color
Blinking
0 1 1 0 0 0 0 1 61 Brown Background Color
Blue Text Color
1 1 1 0 0 0 0 1 0E1 Brown Background Color
Blue Text Color
Blinking
DESIGNING PROGRAMS USING
PROCEDURE
Procedures make it possible to break a
large program down into smaller pieces so
that each piece can be shown to work
correctly without the reference to any of the
others.
DEFINING A PROCEDURE
Every procedure is defined using PROC and
ENDP directives. Since these are
directives, they don’t generate machine
language instructions; rather, PROC and
ENDP are directions to the assembler,
making the beginning and end of a
procedure. In assembly, the first declared
procedure in the program is considered
the major calling procedure.
Format & Example
• Format:
•
• <procedure-name> PROC
• <instruction-1>
• <instruction-2>
• …
• <instruction-n>
• <procedure-name> ENDP
• Example:
•
• MAIN PROC
• CALL P1
• CALL P2
• CALL QUITPROGRAM
• MAIN ENDP
CALLING PROCEDURE
To call a procedure
Format:
CALL <procedure-name>
FINALS
Week 13 – File and Disk handling
Week 14 – Sample Programs in Assembly Language
Week 15 – Math Operation
Week 16 – In-line Assembly
Week 17 – Case Study
FILE AND DISK HANDLING
Topics:
•Common DOS File Handle Services
•File Attributes
•Modes of Accessing Files
Objectives:
• To identify and familiarize with the
different services for file and disk handling.
• To create a program using the different
services in file and disk handling.
• To identify the different file attributes
• To apply the different modes of accessing
files.
Common DOS File Handle
Services
INT 21H / 39H
Create Subdirectory
This service creates a subdirectory as does
the system command MKDIR. To use it,
load DX with the address of an ASCIIZ
string containing the drive and directory
pathname.
AH = 39H
DS:DX = points to ASCIIZ
If CX = 1, AX has error
Example fragment of a program:
ASCstrg DB ‘n:pathname’, 00H ;ASCIIZ string
…
MOV AH,39H ;request create subdirectory
LEA DX,ASCstrg ;Address of ASCIIZ string (DS:DX)
INT 21H
Remove Subdirectory
This service deletes a subdirectory, just as
does the system command RMDIR. Note
that you cannot delete the current (active)
directory or a subdirectory containing files.
Load DX with the address of an ASCIIZ
string containing the drive and directory
pathname.
AH = 3AH
DS:DX = points to ASCIIZ string
IF CX = 1, AX has error
INT 21H / 3AH
Example fragment of a program:
ASCstrg DB ‘n:pathname’,00H ;ASCIIZ string
…
MOV AH,3AH ;request delete subdirectory
LEA DX,ASCStrg ;address of ASCIIZ (DS:DX)
INT 21H ;call interrupt service
INT 21H / 56H
Rename File or Directory
This service name a file or directory from
within a program. Load DX with the
address of an ASCIIZ string containing the
old drive, path and name of the file or
directory to be renamed. Load DI
(combined as ES:DI) with the address of
an ASCIIZ string containing the new drive,
path and name, with no wild cards.
Drive numbers, if used, must be the same in
both strings. Because the paths need not
be the same, the operation can both
rename a file and move it to another
directory on the same drive.
Example fragment of a program:
Oldstring db ‘n:oldpatholdname’,00h
Newstring db ‘n:newpath]newname’,00h
…
MOV AH,56H ;request rename file/directory
LEA DX,Oldstring ;DS:DX
LEA DI,Newstring ;ES:DI
INT 21H / 5BH
Create a new File
This service creates a file only if the
named file does not already exist;
otherwise it is identical to function 3CH
(create file). You could use function 5BH
whenever you don’t want to overwrite an
existing file.
INT 21H / 3CH
Create File
AH = 3CH
DS:DX = points to ASCIIZ string
CX = attribute
File Attributes
BIT ATTRIBUTE
0 Read only file
1 Hidden file
2 System file
3 Volume label
4 Subdirectory
5 Archive file
INT 21H / 43H
Get/Set File Attribute
You can use this operation either to get or
set a file attribute in the directory. This
operation requires the address of an
ASCIIZ string containing the drive, path
and filename for the requested file. (Or
use the default directory if no path is
given.)
Example fragment of a program:
ASCstrg db ‘n:pathname’,00H ;ASCIIZ string
…
MOV AH,43H ;request
MOV AL,00H ;get attribute
LEA DX,ASCstrg ;ASCIIZ string (DS:DX)
INT 21H ;call interrupt service
INT 21H / 3BH
Change Directory
This service changes directory.
AH = 3BH
DS:DX = points to ASCIIZ string
If CX = 1, AX has error
Modes for Accessing Files
Access mode Means
0 Read Only
1 Write Only
2 Both Read and Write
INT 21H / 3DH
Open File
This function opens a file.
AH = 3DH
DS:DX = points to ASCIIZ string
AL = MODE
INT 21H / 3EH
Close File
This service closes a file.
AH = 3EH
BX = file handle
If CX = 1, AX has error
INT 21H / 41H
Delete File
This service deletes a file (but not read-
only) from within a program. Load the
address in DX of an ASCIIZ string
containing the device path and filename,
with no wild cards references.
Example fragment of a program:
ASCstrg db ‘n:pathname’,00H ;ASCIIZ string
…
MOV AH,41H ;request delete file
LEA DX,ASCSTRG ;address of ASCIIZ string (DS:DX)
INT 21H ;call interrupt service
Sample Programs In Assembly
Language
Topic:
• Designing programs using procedure
• Basic Stack Instruction
• Loop Instruction
Objectives:
• Create an assembly program with
procedures.
• Create an assembly program using stack
instruction.
• Create an assembly program using loop
instruction.
DESIGNING PROGRAMS USING
PROCEDURE
• DEFINING A PROCEDURE
Every procedure is defined using PROC and
ENDP directives. Since these are directives,
they don’t generate machine language
instructions; rather, PROC and ENDP are
directions to the assembler, making the
beginning and end of a procedure. In assembly,
the first declared procedure in the program is
considered the major calling procedure.
Format:
<procedure-name> PROC
<instruction-1>
<instruction-2>
…
<instruction-n>
<procedure-name> ENDP
Example:
MAIN PROC
CALL P1
CALL P2
CALL QUITPROGRAM
MAIN ENDP
CALLING PROCEDURE
To call a procedure
Format:
CALL <procedure-name>
Example:
.model small
.code
org 100h
start: jmp main
x db “assembly$”
y db “language$”
z db “program$”
main proc near
mov dx,offset x
call proc1
call proc2
mov dx,offset y
call proc 1
call proc2
mov dx,offset z
call proc1
call proc2
main endp
proc2 proc near
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
ret
proc2 endp
proc1 proc near
mov ah,9
int 21h
ret
proc1 endp
end start
Basic Stack Instruction
Push Instruction
puts/places data onto the stack segment
Pop Instruction
takes out data from the stack
Format:
• push reg16
• pop reg16
• push reg32 (3)
• pop reg32 (3)
• push segreg
• pop segreg (except CS) push memory
• pop memory
• The first two instructions push and pop a
16 bit general purpose register. This is a
compact (one byte) version designed
specifically for registers
• The second pair of instructions push or
pop an 80386 32 bit general purpose
register.
• The third pair of push/pop instructions let
you push or pop an 80x86 segment
register.
• The fourth pair of push/pop instructions
allow you to push or pop the contents of a
memory location.
Example:
.model small
.code
org 100h
start: mov cx,5
x: mov ah,1
int 21h
add al,20h
push ax
loop x
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
mov cx, 5
y: pop dx
int 21h
loop y
int 20h
end start
Loop Instruction
Loop allows a part of the program to be
repeated for several times, the number of
loops depend on the value of the CX
register.
- each time the loop is executed, CX is
decremented and the looping stops when
CX becomes zero.
Format:
LOOP label
Example:
LOOP start
This will cause the program flow
to go to the label start for CX times.
Example:
.model small
.code
org 100h
start:mov cx,20
mov ah,2
mov dl, ‘j’
z: int 21h
loop z
end start
Math Operation
• BCD
• ASCII
Objectives:
• To create a program using addition,
subtraction, multiplication and division of
Binary Coded Decimal.
• To create a program that converts the
addition, subtraction of ASCII codes to
BCD.
• To identify the instructions and directives
for addition, subtraction of BCD.
BCD
• binary coded decimals
Binary coded decimal (BCD) is a
method for implementing lossless decimal
arithmetic (including decimal fractions) on
a binary computer. The most obvious uses
involve money amounts where round-off
error from using binary approximations is
unacceptable. Some early computers
used BCD exclusively.
•
• Decimal digits (0-9) can be encoded in a nibble
(half a byte), with some left over bit patterns
(hexadecimal A-F). In BCD operations, the
processor performs ordinary binary
computations, then adjusts the result to conform
to BCD.
• For example, if you add the binary number 5 (bit
pattern 0101) to binary number 6 (bit pattern
0110), you get the binary result of 11 (bit pattern
1011, or hexadecimal B). With BCD arithmetic,
the processor would adjust the result to make it
into a valid BCD result (which in this case would
be bit pattern 0001 0001).
• BCD arithmetic includes BCD addition, BCD
subtraction, BCD multiplication, BCD division, and
BCD negate.
The Intel 80x86 series uses a two step approach
for BCD arithmetic. Instead of having separate
BCD instructions, the normal binary addition and
subtraction instructions are used, then hardware
instructions are used to adjust the results to
correct BCD results.
• There are instructions for both packed and
unpacked adjustments.
• The advantage of this approach is greater
flexibility (more addressing modes and choices
of arithmetic operations because of the use of
regular binary integer instructions in the first
step).
• The disadvantage of this approach is that it is
slower and takes more memory.
ASCII
• American Standard Character Information
Interchange.
• Refer to ASCII Table
Adding ASCII Numbers
Consider the effect of the following three examples of
adding ASCII numbers:
Ex. 1 35H Ex.2 38H Ex.3 39H
+32H 34H +39H
Total 67H 6CH 72H
Example 1.
The sum of 35h and 32h is 67h. AAA
checks the rightmost digit (7). Because it
is not between A and F, nor is the AF flag
set, AAA clears the leftmost digit (6) to 0.
Example 2. The sum of 38H and 34 H is
6CH. Because the right most digit (C) is
between A and F, AAA performs the
following:
AH AL
00 0C
Adds 6 to AL 00 72
Adds 1 to H 01 72
Clears leftmost digit of AL 01 02 (sum = 12)
Example 3. The sum of 39H and 39H is 72H.
Although the rightmost digit (2) is not between
A and F, the AF flag is set because of the carry
into the tens position. AAA performs the
following:
AH AL
00 72
Adds 6 to AL 00 78
Adds 1 to AH 01 78
Clears leftmost digit of AL 01 08 (sum = 18)
Subtracting ASCII NUMBERS
Example 1. ASCIIvalue1 contains 39h and ASCII value2
contains 39h. Subtracts ASCIIvalue2 (35h) from
ASCIIvalue1 (39h). AAS does not need to make an
adjustment because the rightmost hex digit is less than
the hex A.
AX AF CF
MOV AL,ASCVALUE1 ; 0039
SUB AL,ASCVALUE2 ; 0004 0 0
AAS ; 0004 0 0
OR AL,30h ; 0034
Example 2. Subtracts ASCIIvalue1 (39h) from ASCII value2
(35h). Because the rightmost digit of the result is hex C,
AAS subtracts 6 from AL, subtracts 1 from AH, and sets
the AF and CF flags:
AX AF CF
MOV AL,ASCVALUE2 ; 0035
SUB AL,ASCVALUE1 ; 00FC 1 1
AAS ; FFO6 1 1
The answer, which should be -4, is FF06h, its ten’s
complement; that is, decimal -10 + 6 = -4.
Multiplying ASCII Numbers
INSTRUCTION COMMENT AX CL
. . . ; Initial values 0035 39
AND CL, 0FH ; Convert CL to 09 0035 09
AND AL, 0FH ; Convert CL to 05 0005 09
MUL CL ; Multiply AL by CL 002D 09
AAM ; Convert AX to unpacked BCD
OR AX 3030H ; Convert AX to ASCII 3435
Dividing ASCII Numbers
INSTRUCTION COMMENT AX CL
. . . ; Initial values 3238 37
AND CL,0FH ; Convert to unpacked BCD 3238 07
AND AX,0FH0FH ; Convert to unpacked BCD 0208
AAD ; Convert to binary 00IC
DIV CL ; Divide by 7 0004
CONVERTING BINARY DATA TO
ASCII FORMAT
• The following example converts binary number
0DF1H to ASCII format:
ASCVALUE DB 4 DUP (‘ ‘) ; Data Items
BINVALUE DW 0DF1H
. . .
MOV CX, 0010 ; Division factor
LEA SI, ASCVALUE ;Address of SCVALUE
MOV AX, BINALUE ; Get binary amount
L20:
CMP AX,CX ; Value < 10?
JB L30 ; yes, exit
XOR DX,DX ; Clear upper quotient
DIV CX ; Divided by 10
OR DL,30H
MOV [SI],DL ; Store ASCII character
DEC SI
JMP L20
L30:
OR AL,30H ;Store last quotient
MOV [SI], AL ; as ASCII character
C20: mov al,[SI] ;get a byte
Shr al,04 ;shift off right hex digit
Lea bx,xlatab ;set table address
Xlat ; translate hex
Stosb ;store AL in DISPAREA
Mov al,[SI] ;get other half of byte
And al,0fh ;clear left hex digit
Xlat ;translate hex
Stosb ;store AL in DISPAREA
Inc SI ; incr address of IOBUFFER
Lea bx,IOBUFFER+512 ;
Cmp SI,BX ;end of IOBUFFER?
Jb c20 ;if no, repeat
Lea bp,disparea ;if yes, display
Mov cx,1024 ;hex characters
Call D10DISPLAY
ret
C10CONVRT endp
; display data:
; - - - - - - - - - ;uses AX, BX, DX
D10DISPLAY proc near ;BP, CX set on entry
MOV AX,1301 ;request display
MOV BX,0016H ;page:attribute
MOV DX,0500H ;row:column
RET
D10DISPLAY end p
End A10MAIN
In-Line Assembly
Topic:
• Comparison of C Language to
Assembly
Objective:
• To construct a program with the
integration of Pascal and C language
programming.
Comparison of C Language To
Assembly Language
If..Else Construct
A conditional statement of C language in the form:
If <condition>
{
<statement-1>;
<statement-2>;
. . .
<statement-n>;
}
Else
{
<statement-1>;
<statement-2>;
. . .
<statement-n>;
}
Can be implemented by assembly language
of the form:
<cmp instruction>
<conditional jump instruction> <label-1>
<instruction-1>
<instruction-2>
…
<instruction-n>
<jump instruction> <label-2>
Comparison
C language Assembly language
If (ax == 0)
{
cx = cx – ax;
ax = ax + 1;
}
Else
{
Cx = cx – 8;
}
CMP AX,0000H
JNZ ACTION1
SUB CX,AX
INC AX
JMP NEXT
ACTION1: SUB CX,0008H
NEXT:
Do..While Construct
A do..while loop similar to C language:
do
{
<statement-1>;
<<statement-2>;
…
<statement-n>;
} while <condition>;
Can be implemented by assembly in the form:
<label>: <instruction-1>
<instruction-2>
…
<instruction-n>
<cmp instruction>
<conditional jump instruction> <label>
Comparison
C language Assembly language
ax = 5;
do
{
ax = ax – 1;
bx = bx + 1;
} while (ax >= 0);
MOV AX,0005H
HERE: DEC AX
INC BX
CMP AX
JNZ HERE
While Construct
Similarly, C language while loop:
While <condition>
{
<statement-1>;
<statement-2>;
…
<statement-n>;
}
Is roughly equivalent to the assembly language
structure:
<label-1>: <cmp instruction>
<conditional jump instruction> <label>
<instruction-1>
<instruction-2>
. . .
<instruction-n>
jmp <label-1>
<label-2>: <instruction-1>
<instruction-2>
. . .
<instruction-n>
Comparison
C language Assembly language
while (ax <= 10)
{
ax = ax + bx;
bx = bx + 1;
}
START: CMP AX,000AH
JGE NEXT
ADD AX,BX
INC BX
JMP START
NEXT: ADD CX,AX
Final Case Study
Design a problem that will utilize
any of the constructs if-else, do-
while and while. Please don’t
forget to check the complexity
and eventual completeness of
your output.
Objective:
• To develop programs that apply the whole
concepts of assembly programming.
Final Examination
and
Case Presentation
ENDEND

Weitere ähnliche Inhalte

Was ist angesagt?

Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМ
Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМПрограммирование на языке C Sharp (СИ решетка) ПРАКТИКУМ
Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМAlexandr Konfidentsialno
 
The code on wages 2019
The code on wages 2019 The code on wages 2019
The code on wages 2019 rahman147
 
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...satyabrata patro
 
Recent Amendments in Labour Law
Recent Amendments in Labour LawRecent Amendments in Labour Law
Recent Amendments in Labour LawSameer Sayyad
 
Contract Labour (Regulation And Abolition) Act, 1970
Contract Labour (Regulation And Abolition) Act, 1970Contract Labour (Regulation And Abolition) Act, 1970
Contract Labour (Regulation And Abolition) Act, 1970Dr. Trilok Kumar Jain
 
The payment of gratuity act
The payment of gratuity actThe payment of gratuity act
The payment of gratuity actARUNAYESUDAS
 
Code on wages, 2019
Code on wages, 2019Code on wages, 2019
Code on wages, 2019CADHEERAJN
 
The payment of wages act 1936
The payment of wages act 1936The payment of wages act 1936
The payment of wages act 1936Management
 
Pseudo code practice problems+ c basics
Pseudo code practice problems+ c basicsPseudo code practice problems+ c basics
Pseudo code practice problems+ c basicsakshay kumar
 
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣ
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣκεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣ
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣGeorgia Sofi
 
The Payment Of Gratuity Act, 1972
The Payment Of Gratuity Act, 1972The Payment Of Gratuity Act, 1972
The Payment Of Gratuity Act, 1972satyam mishra
 
Het Rijnlands Model
Het Rijnlands ModelHet Rijnlands Model
Het Rijnlands Modelguest0d9398
 
Occupational Health and safety and code, 2020.pptx
Occupational Health and safety and code, 2020.pptxOccupational Health and safety and code, 2020.pptx
Occupational Health and safety and code, 2020.pptxdhruvsharma670402
 

Was ist angesagt? (16)

Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМ
Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМПрограммирование на языке C Sharp (СИ решетка) ПРАКТИКУМ
Программирование на языке C Sharp (СИ решетка) ПРАКТИКУМ
 
Code on wages act,2019
Code on wages act,2019Code on wages act,2019
Code on wages act,2019
 
The code on wages 2019
The code on wages 2019 The code on wages 2019
The code on wages 2019
 
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...
THE INTER-STATE MIGRANT WORKMEN(REGULATION OF EMPLOYMENT AND CONDITIONS OF SE...
 
Recent Amendments in Labour Law
Recent Amendments in Labour LawRecent Amendments in Labour Law
Recent Amendments in Labour Law
 
Contract Labour (Regulation And Abolition) Act, 1970
Contract Labour (Regulation And Abolition) Act, 1970Contract Labour (Regulation And Abolition) Act, 1970
Contract Labour (Regulation And Abolition) Act, 1970
 
Payment Of Wages Final
Payment Of Wages FinalPayment Of Wages Final
Payment Of Wages Final
 
types of incentives.pdf
types of incentives.pdftypes of incentives.pdf
types of incentives.pdf
 
The payment of gratuity act
The payment of gratuity actThe payment of gratuity act
The payment of gratuity act
 
Code on wages, 2019
Code on wages, 2019Code on wages, 2019
Code on wages, 2019
 
The payment of wages act 1936
The payment of wages act 1936The payment of wages act 1936
The payment of wages act 1936
 
Pseudo code practice problems+ c basics
Pseudo code practice problems+ c basicsPseudo code practice problems+ c basics
Pseudo code practice problems+ c basics
 
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣ
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣκεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣ
κεφαλαιο 2: ΔΙΚΟΜΜΑΤΙΣΜΟΣ - ΕΚΣΥΓΧΡΟΝΙΣΜΟΣ
 
The Payment Of Gratuity Act, 1972
The Payment Of Gratuity Act, 1972The Payment Of Gratuity Act, 1972
The Payment Of Gratuity Act, 1972
 
Het Rijnlands Model
Het Rijnlands ModelHet Rijnlands Model
Het Rijnlands Model
 
Occupational Health and safety and code, 2020.pptx
Occupational Health and safety and code, 2020.pptxOccupational Health and safety and code, 2020.pptx
Occupational Health and safety and code, 2020.pptx
 

Ähnlich wie Kaizen cso002 l1

Digital electronics-Introduction.pptx
Digital electronics-Introduction.pptxDigital electronics-Introduction.pptx
Digital electronics-Introduction.pptxSubrata Maiti
 
Chapter 1 digital design.pptx
Chapter 1 digital design.pptxChapter 1 digital design.pptx
Chapter 1 digital design.pptxAliaaTarek5
 
Introduction to Microprocessor lecture 01
Introduction to Microprocessor lecture  01Introduction to Microprocessor lecture  01
Introduction to Microprocessor lecture 01Md. Murshedul Arifeen
 
computer logic and digital design chapter 1
computer logic and digital design chapter 1computer logic and digital design chapter 1
computer logic and digital design chapter 1tendaisigauke3
 
Microproccesor and Microcontrollers hardware basics
Microproccesor and Microcontrollers hardware basicsMicroproccesor and Microcontrollers hardware basics
Microproccesor and Microcontrollers hardware basicsashmus
 
21EC201– Digital Principles and system design.pptx
21EC201– Digital Principles and system design.pptx21EC201– Digital Principles and system design.pptx
21EC201– Digital Principles and system design.pptxGobinathAECEJRF1101
 
03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdfvijayapraba1
 
Numbersystemcont
NumbersystemcontNumbersystemcont
NumbersystemcontSajib
 
Chapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.pptChapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.pptKalGetachew2
 
Chapter 1 Digital Systems and Binary Numbers.ppt
Chapter 1 Digital Systems and Binary Numbers.pptChapter 1 Digital Systems and Binary Numbers.ppt
Chapter 1 Digital Systems and Binary Numbers.pptAparnaDas827261
 

Ähnlich wie Kaizen cso002 l1 (20)

microprocessor
microprocessormicroprocessor
microprocessor
 
Digital electronics-Introduction.pptx
Digital electronics-Introduction.pptxDigital electronics-Introduction.pptx
Digital electronics-Introduction.pptx
 
microprocessors
microprocessorsmicroprocessors
microprocessors
 
DLD-Introduction.pptx
DLD-Introduction.pptxDLD-Introduction.pptx
DLD-Introduction.pptx
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
 
Chapter 1 digital design.pptx
Chapter 1 digital design.pptxChapter 1 digital design.pptx
Chapter 1 digital design.pptx
 
Introduction to Microprocessor lecture 01
Introduction to Microprocessor lecture  01Introduction to Microprocessor lecture  01
Introduction to Microprocessor lecture 01
 
Chapter1.ppt
Chapter1.pptChapter1.ppt
Chapter1.ppt
 
computer logic and digital design chapter 1
computer logic and digital design chapter 1computer logic and digital design chapter 1
computer logic and digital design chapter 1
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
 
Microproccesor and Microcontrollers hardware basics
Microproccesor and Microcontrollers hardware basicsMicroproccesor and Microcontrollers hardware basics
Microproccesor and Microcontrollers hardware basics
 
21EC201– Digital Principles and system design.pptx
21EC201– Digital Principles and system design.pptx21EC201– Digital Principles and system design.pptx
21EC201– Digital Principles and system design.pptx
 
03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdf
 
Numbersystemcont
NumbersystemcontNumbersystemcont
Numbersystemcont
 
Lecture 1& 2.pptx
Lecture 1& 2.pptxLecture 1& 2.pptx
Lecture 1& 2.pptx
 
Chapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.pptChapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.ppt
 
Number systems r002
Number systems  r002Number systems  r002
Number systems r002
 
Digital logic design part1
Digital logic design part1Digital logic design part1
Digital logic design part1
 
Chapter 1 Digital Systems and Binary Numbers.ppt
Chapter 1 Digital Systems and Binary Numbers.pptChapter 1 Digital Systems and Binary Numbers.ppt
Chapter 1 Digital Systems and Binary Numbers.ppt
 

Kürzlich hochgeladen

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Kürzlich hochgeladen (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Kaizen cso002 l1

  • 2. COMPUTER SYSTEM ORGANIZATION Prelim Midterm Finals Kaizen 2006 - 2007 TERMS
  • 3. PRELIM Week 1 – Microprocessor Week 2 – Basic Structure of hardware and Softw Week 3 – Register Week 4 – System Operation Week 5 - Editor
  • 4. Microprocessors Topics: 1.Microprocessor 2.History of Microprocessors 3.Types of Microprocessors 4.Number System * Decimal * Binary * Octal * Hexadecimal
  • 5. Objectives •To define what is a microprocessor. • To discuss the history of microprocessor. • Identify the types of microprocessor • To recall numbers systems.
  • 6. Microprocessors The brain or engine of the PC is the processor (sometimes called microprocessor), or central processing unit (CPU). The CPU performs the system's calculating and processing.
  • 7. Brief History • Intel is generally credited with creating the first microprocessor in 1971 with the introduction of a chip called the 4004. • All PC-compatible systems use either Intel processors or Intel- compatible processors from a handful of competitors Example: AMD or Cyrix. •Late 1970s the two most popular processors for PCs were not from Intel (although one was a clone of an Intel processor). Personal computers of that time primarily used the Z-80 by Zilog and the 6502 by MOS Technologies. • Z-80 was noted for being an improved and less expensive clone of the Intel 8080 processor, similar to the way companies today such as AMD, Cyrix, IDT, and Rise Technologies have cloned Intel's Pentium processors.
  • 8. Types of Microprocessor Processors can broadly be divided into the categories of: CISC, RISC, hybrid, and special purpose. Complex Instruction Set Computers (CISC) have a large instruction set, with hardware support for a wide variety of operations. In scientific, engineering, and mathematical operations with hand coded assembly language (and some business applications with hand coded assembly language), CISC processors usually perform the most work in the shortest time.
  • 9. Reduced Instruction Set Computers (RISC) have a small, compact instruction set. In most business applications and in programs created by compilers from high level language source, RISC processors usually perform the most work in the shortest time. Hybrid processors are some combination of CISC and RISC approaches, attempting to balance the advantages of each approach. Special purpose processors are optimized to perform specific functions. Digital signal processors and various kinds of co- processors are the most common kinds of special purpose processors.
  • 10. Function of Microprocessor • To coordinate the functioning of the various components of the system by generating and responding to control signals and to perform various arithmetic and logic functions.
  • 11. Number Systems Decimal, Binary, Octal and Hexadecimal Numeric Systems. Conversions among the different systems
  • 12. Decimal Numbering systems Base: 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • 13. Example: 523410 103 = 1000 102 = 100 101 = 10 100 = 1 5 2 3 4 5,234 = 5 x 1000 + 2 x 100 + 3 x 10 + 4 x 1
  • 14. Binary Numbering systems • Base: 2 • Digits: 0, 1 • binary number: 1101012 positional powers of 2: 25 24 23 22 21 20 decimal positional value: 32 16 8 4 2 1 binary number: 1 1 0 1 0 1
  • 15. Binary to Decimal Conversion • To convert to base 10, add all the values where a one digit occurs. Ex: 1101012 positional powers of 2: 25 24 23 22 21 20 decimal positional value: 32 16 8 4 2 1 binary number: 1 1 0 1 0 1 32 + 16 + 4 + 1 = 5310
  • 16. Ex: 1010112 positional powers of 2: 25 24 23 22 21 20 decimal positional value: binary number:
  • 17. Ex: 1010112 positional powers of 2: 25 24 23 22 21 20 decimal positional value: 32 16 8 4 2 1 binary number: 1 0 1 0 1 1 32 + 8 + 2 + 1 = 4310
  • 18. The Division Method. Divide by 2 until you reach zero, and then collect the remainders in reverse. Ex 1: 5610 = 1110002 2 ) 56 Rem: 2 ) 28 0 2 ) 14 0 2 ) 7 0 2 ) 3 1 2 ) 1 1 0 1
  • 19. Ex 2: 3510 = 2 ) Rem: 2 ) 2 ) 2 ) 2 ) 2 ) Answer: 3510 = 2
  • 20. Character Representation Ex: Find the binary ASCII and decimal ASCII values for the ‘&’ character. Rightmost Leftmost Three Bits Four Bits 000 001 010 011 100 101 110 111 0000 NUL DLE Space 0 @ P ` p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 " 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN && 6 F V f v 0111 BEL ETB ' 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y I y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL
  • 21. Character Representation ASCII Table From the chart: ‘&’ = 0100110 (binary ASCII value) Convert the binary value to decimal: 01001102 = 32 + 4 + 2 = 3810 Therefore: ‘&’ = 38 (decimal ASCII value)
  • 22. Octal Numbering systems • Base: 8 • Digits: 0, 1, 2, 3, 4, 5, 6, 7 • Octal number: 12468 powers of : 84 83 82 81 80 decimal value: 4096 512 64 8 1 Octal number: 1 2 4 6
  • 23. Octal to Decimal Conversion • To convert to base 10, beginning with the rightmost digit multiply each nth digit by 8(n-1) , and add all of the results together. Ex: 12468 positional powers of 8: 83 82 81 80 decimal positional value: 512 64 8 1 Octal number: 1 2 4 6 512 + 128 + 32 + 6 = 67810
  • 24. Ex: 103528 positional powers of 8: 84 83 82 81 80 decimal positional value: Octal number:
  • 25. The Division Method. Divide by 8 until you reach zero, and then collect the remainders in reverse. Ex 1: 433010 = 103528 8 ) 4330 Rem: 8 ) 541 2 8 ) 67 5 8 ) 8 3 8 ) 1 0 0 1
  • 26. Ex 2: 81010 = 8 ) 810 Rem: 8 ) 8 ) 8 ) Answer: 81010 = 8
  • 27. Hexadecimal Numbering systems • Base: 16 • Digits: 0, 1, 2, 3, 4, 5, 6, 7,8,9,A,B,C,D,E,F • Hexadecimal number: 1F416 powers of : 164 163 162 161 160 decimal value: 65536 4096 256 16 1 Hexadecimal number: 1 F 4
  • 28. Four-bit Group Decimal Digit Hexadecimal Digit 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F
  • 29. Hexa to Decimal Conversion • To convert to base 10, beginning with the rightmost digit multiply each nth digit by 16(n-1) , and add all of the results together. Ex: 1F416 positional powers of 16: 163 162 161 160 decimal positional value: 4096 256 16 1 Hexadecimal number: 1 F 4 256 + 240 + 4 = 50010
  • 30. Ex: 7E16 positional powers of 16: 163 162 161 160 decimal positional value: Hexa number:
  • 31. • The Division Method. Divide by 16 until you reach zero, and then collect the remainders in reverse. Ex 1: 12610 = 7E16 16) 126 Rem: 16) 7 14=E 0 7
  • 32. Ex 2: 81010 = 16 ) 810 Rem: 16 ) 16 ) Answer: 81010 = 16
  • 33. Binary to Octal Conversion • Since the maximum value represented in 3 bit is equal to: 23 – 1 = 7 • i.e. using 3 bits we can represent values from 0 –7 which are the digits of the Octal numbering system. • Thus, three binary digits can be converted to one octal digit and visa versa.
  • 34. Three-bit Group Decimal Digit Octal Digit 000 0 0 001 1 1 010 2 2 011 3 3 100 4 4 101 5 5 110 6 6 111 7 7
  • 35. Ex : Convert 7428 = 2 7 = 111 4 = 100 2 = 010 7428 = 111 100 0102
  • 36. Ex : Convert 101001102 = 8 110 = 6 100 = 4 010 = 2 ( pad empty digits with 0) 101001102 = 2468
  • 37. Four-bit Group Decimal Digit Hexadecimal Digit 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F
  • 38. Ex : Convert 3D916 = 2 3 = 0011 D = 1101 9 = 1001 3D916 = 0011 1101 10012
  • 39. Ex : Convert 101001102 = 16 0110 = 6 1010 = A 101001102 = A616
  • 40. To convert between Octal to Hexadecimal numbering systems and visa versa convert from one system to binary first then convert from binary to the new numbering system
  • 41. Ex : Convert E8A16 = 8 1110 1000 10102 111 010 001 010 (group by 3 bits) 7 2 1 2 E8A16 = 72178
  • 42. Ex : Convert 7528 = 16 111 101 0102 (group by 4 bits) 0001 1110 1010 1 E A 7528 = 1EA16 Ex : Convert 7528 = 16 111 101 0102 (group by 4 bits) 0001 1110 1010 1 E A 7528 = 1EA16
  • 43.
  • 44. Basic Structure of hardware and Software Topics: • Internal Hardware Features • External Hardware Features • Program Organization • Memory Organization • Basics of Assembly Programming • SK Editor • Using Debug
  • 45. Objectives • To familiarize with the basic structure of hardware and software • To discuss programming model and memory organization • To discuss assembly programming using debug.
  • 46. Basic Structure of Hardware and Software Hardware – is the physical part of the computer system Software - A program or set of instructions that controls the operation of a computer. Distinguished from the actual hardware of the computer.
  • 47. Internal Hardware Features 1. Processor 2. Memory 3. Registers
  • 48. External Hardware Features Computer’s Input/Output example: 1. Keyboard 2. Monitor 3. Disk 4. CD-ROM
  • 49. Program Organization • Software consists of the operating system and various programs and data files stored on disk. • To execute (or run) a program: 1. the system copies it from external device into internal memory. 2. the processor executes the program instructions. 3. The registers handle the requested arithmetic, data movement, and addressing.
  • 50. Memory Organization Bit – the fundamental building block of computer storage - off means 0, on means 1 Bytes – consists of eight bits for data and one bit for parity 0 0 0 0 0 0 0 0 1 Data bits parity According to the rule of parity, the number of bits that are on in each byte must always be odd.
  • 51. Related Bytes • A program can treat a group of one or more related bytes as a unit of data, such as time or distance. A group of bytes that defines a particular value is commonly known as a data item or field. • Word – a 2-byte (16-bit) data item • Doubleword – A 4-byte (32-bit) data item • Quadword – An 8-byte (64-bit) data item
  • 52. • Paragraph – a 16-byte (128 bit) area • Kilobyte (KB) – The number 210 equals, 1,024, which happens to be the value K, for kilobyte. • Megabyte (MB) – The number 220 equals 1,048,576, or 1 megabyte.
  • 53. Basics of Assembly Programming Programming Language A programming language is a notation for expressing instructions to be carried out by the computer. It is a medium of communication between the human and the machine, and often between one human being and another.
  • 54. Classification of programming Languages • High-Level Language – A high-level language is an English-like language that provides for more natural expression of algorithms. Examples: BASIC, Pascal, COBOL, & Prolog • Mid-level Language– It is a computer language which combines low-level efficiency with high-level language structure, abstraction and portability. Examples: C & MODULO-2 • Low-level Language – A low-level language is considered to be machine-oriented since it is closely follows the built in instruction set of the underlying computer. Examples: Assembly, machine languages.
  • 55. Assembly Language • It is a low-level language that provides a kind of shorthand notation called mnemonic (memory aid) for the actual machine language instruction. It is a much easier to remember SUB AX<BX than 0010101111000011 which is the actual instruction code that the machine uses.
  • 56. SideKick Editor • It is a text editor used in coding the source code. SideKick or SK editor can display the ASCII code for coding assembly language program.
  • 57. Debug • BUG - It is a computer terminology for error or mistake in a program or computer system and the term debugging is a methodical process of finding and reducing the number of bugs or defects in a computer program. • DEBUGGER – It is a program tool that provides an environment for testing load modules. Load modules are executable programs
  • 58.
  • 59. Registers Topics: 1. Register 2. General Purpose Registers 3. Pointer Registers 4. Segment Registers 5. Index Registers 6. Flag Registers
  • 60. Objectives 1. To define what is a register. 2. Identify the types of registers. 3. Identify the function of each register.
  • 61. Register Set Registers are fast memory, almost always connected to circuitry that allows various arithmetic, logical, control, and other manipulations, as well as possibly setting internal flags.
  • 62. General-Purpose Registers AX - Accumulator Register mostly used for calculations and for input/output BX - Base Register Only register that can be used as an index AH AL AX EAX BH BL BX EBX
  • 63. • CX - Count Register used for the loop instruction • DX - Data Register input/output and used by multiply and divide CH CL CX ECX DH DL DX EDX
  • 64. Pointer Registers IP - Instruction Pointer 16-bit number that points to the offset of the next instruction SP - Stack Pointer 16-bit number that points to the offset that the stack is using BP - Base Pointer used to pass data to and from the stack
  • 65. Segment Registers CS - Code Segment 16-bit number that points to the active code-segment DS - Data Segment 16-bit number that points to the active data-segment SS - Stack Segment 16-bit number that points to the active stack-segment ES - Extra Segment 16-bit number that points to the active extra-segment
  • 66. Index Registers SI - Source Index used by string operations as source DI - Destination Index used by string operations as destination
  • 67. Flag Registers Abr. Name bit nº Description OF Overflow Flag 11 indicates an overflow when set DF Direction Flag 10 used for string operations to check direction IF Interrupt Flag 9 if set, interrupt are enabled, else disabled TF Trap Flag 8 if set, CPU can work in single step mode SF Sign Flag 7 if set, resulting number of calculation is negative ZF Zero Flag 6 if set, resulting number of calculation is zero AF Auxiliary Carry 4 some sort of second carry flag PF Parity Flag 2 indicates even or odd parity CF Carry Flag 0 contains the left-most bit after calculations
  • 68.
  • 69. System Operation Topics: • Disk Operating System • Debug • Loading of Debug from DOS • Loading SK through DOS
  • 70. Objectives • To recall common DOS commands. • To discuss the procedures in starting and quitting Debug. • To familiarize with the Debug commands. • To know the rules in using debug commands.
  • 71. System Operation Common Disk Operating System Commands 1. CLS - clear 5. DEL - delete 2. CD – change dir 6. REN - rename 3. DIR - directory 7. MD – make directory 4. COPY - copy 8. RD – remove directory
  • 72. DEBUG Debug – is a software that is classified as debugger which is used for testing and debugging executable programs. - It displays all program code and data in hexadecimal format and any data that you enter into memory must also in hex form.
  • 73. Advantages of Debug 1. It is free. 2. It is universally available. 3. It is simple to use. 4. It requires relatively little memory.
  • 74. Debug Commands 1. Q (Quit) Finishes the Debug session and exits back to DOS environment Ex: -Q 2. H (Hexarithmetic) Shows the sum and difference of two 4-bit hexadecimal numbers, coded as H <hex value> <hex value> Ex: - 000C 0008
  • 75. 3. R (Register) Allows you to display all registers and their values. It also shows the next instruction and permits you to change the value of a particular register. Ex: -R -R CX 4. E (Enter) Enables you to key in data or machine instructions into memory beginning at a specific location address. Ex: -E 0200
  • 76. 5. D (Display or Dump) Displays the content 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. It also translates this assembly source statements that you create into machine code. Ex: -A 0100
  • 77. 7. T (Trace) Runs the program in a 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
  • 78. 9. U (Unassemble) Lists all the instructions contained in the program beginning at the given address. You can also specify the last address location. Ex: -U 0100 -U 0100 0109 10.N (Name) Gives a name to your program, coded as N <path><filename>. The base name of the filename must be eight characters long and the extension name is .COM Ex: N A:SAMPLE>COM
  • 79. 11.W (Write) Saves the program onto the disk storage. Ex: -W
  • 80. Rules of Debug Commands •It is not case sensitive •It assumes that all numbers given are in hexadecimal format. •You can enter a space only when it is needed to separate parameters of a particular command. •You should specify segments and offsets with a colon, in the form <segment>:<offset>.
  • 81. Starting Debug 1. Key in the word debug and press enter. A hyphen (-) appears on the screen, that is the DEBUG prompt. DEBUG is now ready to accept commands. C:>debug -
  • 82. Quitting and Closing Debug To close Debug and go back to DOS environment: type Q and press ENTER key. C:>debug -q C:>
  • 83. Loading SK Through DOS • From the C:> prompt type SK then the SideKick main menu will appear. From the menu select Notepad or press F2. C:>sk
  • 84. Basic Assembly Instructions Used in Debug 1. MOV (Move data) It copies and transfers data between two registers, or between an immediate data to a register. Format: MOV <register>,<register> MOV <register>, <immediate data>
  • 85. Example: MOV AX,BX MOV CX, 5083 MOV CL,DL MOV BL,33 2. ADD (Add Data) It is used to get the sum of two registers or a register and an immediate data, and stores the result to the left most register.
  • 86. Format: ADD <register>,<register> ADD <register>,<immediate data> Example: ADD CX,BX ADD AX,0308 ADD AL,BL ADD DH, 95 3. SUB (Subtract Data) It is used to get the difference of two registers or a register and an immediate data, and stores the result to the left most register.
  • 87. Format: SUB <register>,<register> SUB <register>,<immediate data> Example: SUB CX,BX SUB AX,0308 SUB AL,BL SUB CL,95 3. MUL (Multiply Data) It is used to get the product of the given register and AX register, and stores the result to AX register. If the product is greater than 16 bits, the overflow is stored in DX register.
  • 88. Format: MUL <register> Example: MUL CX 5. DIV (Divide Data) It is used to divide the value of a given register and AX register, and stores the quotient to AX and the remainder to DX registers respectively. Format: DIV <register> Example: DIV BX
  • 89. 6. INC (Increment by one) It is used to increase the value of the register by one (1). Format: INC <register> Example: INC AX INC CH 7. DEC (Decrement by one) The opposite of INC, instead of increasing, it decreases the value of the register by one (1)
  • 90. Format: DEC <register> Example: DEC AX DEC CH 8. LOOP (Loop Until Complete) It controls the execution of a program segment in a specified number of times. The CX register should contain a count value before starting the loop and automatically decrements by one (1). If CX is not equal to zero (0), it transfers to its operand address which points to the start of the loop; otherwise it drops through to the next instruction.
  • 91. Format: LOOP <offset address> Example: LOOP 0108
  • 92. Sample Debug Programs Displaying a smiley character on the screen. -A 0100 1358:0100 mov ah,02 ;request display character 1358:0102 mov dl,01 ;character to display 1358:0104 int 21 ;call interrupt service 1358:0106 int 20 ;end 13587:008 -G Program terminated normally -
  • 93. Using control characters (0A – Line Feed and 0D – Carriage Return) in a screen display. -A 0100 1358:0100 MOV AH, 02 ;request display character 1358:0102 MOV DL,54 ;character ‘T’ 1358:0104 INT 21 ;call interrupt service 1358:0106 MOV DL, 0A ;line feed character 1358:0108 INT 21 ;call interrupt service 1358:010A MOV DL,0D ;carriage return character 1358:010C INT 21 ;call interrupt service 1358:010E MOV DL,49 ;character ‘I’ 1358:0110 INT 21 ;call interrupt service 1358:0112 MOV DL,0A ;line feed character 1358:0114 INT 21 ;call interrupt service 1358:0106 MOV DL,0D ;carriage return character 1358:0118 INT 21 ;call interrupt service 1358:011A MOV DL,50 ;character ‘P’ 1358:011C INT 21 ;call interrupt service 1358:011E INT 20 ;end
  • 94. Displaying the same character (lowercase ‘z’) thirty times using loop on the screen. -A 0100 1358:0100 MOV CX,001E ;SETTING THE NUMBER OF LOOOPS 1358:0103 MOV AH,2 ;REQUEST DISPLAY CHARACTER 1358:0105 MOV DL,7A ;CHARCTER TO DISPLAY 1358:0107 INT 21 ;CALL INTERRUPT SERVICE 1358:0109 LOOP 0107 ;GO TO OFFSET 0107 1358:010B INT 20 ;END
  • 95.
  • 96. Editor Topics: 1. Editor 2. Types of language translator 3. Advantages of assembly language
  • 97. Objectives • To identify the different editors used in assembly language. • Differentiate the different types of language translator. • Enumerate the advantages of assembly language.
  • 98. Editor Text Editors used in Turbo Assembler 1. Edit 2. Sidekick 3. Pilot
  • 100. Types of language Translator 1. Compiler – Is a translator program that transforms an entire source program composed of high/mid-level language statements into an object program consisting of machine language executable code. High/Mid-level language Source Program COMPILER Machine language Instruction
  • 101. 2. Interpreter – processes the source program on a statement-by-statement basis. It translates high/mid-level language statements and then executes it one statement at a time. 2. Assembler – is a language translator that transforms assembly language to machine language instruction. High/Mid-level language Source Program INTERPRETER Machine language Instruction Assembly language Source Program ASSEMBLER Machine language Instruction
  • 102. Assembly Language It is a low-level language that provides a kind of shorthand notation called mnemonic(memory aid) for the actual machine language instruction. It is much easier to remember SUB, AX, BX than 00101111000011 which is the actual instruction code that machine uses…
  • 103. Advantages of Assembly language •It provides more control over handling particular hardware requirements. • It generates smaller, more compact executable modules. • It results in faster execution.
  • 104. Tasm – Turbo Assembler T-link t - Turbo Assembler Linker Linker is a computer program for high, mid, and low levels of programming language that completes the process by converting the object code into executable machine code.
  • 105. STRUCTURE OF AN ASSEMBLY LANGUAGE PROGRAM TITLE MYPROG.ASM DOSSEG . MODEL SMALL . STACK 0100h . DATA X DB “Hello everyone! $” . CODE MOV AX, @DATA MOV DS, AX MOV AH, 09h MOV DX, OFFSET X MOV AX, 4C00h INT 21h END
  • 106. INSTRUCTIONS FOR INITIALIZING THE PROGRAM TITLE MYPROG.ASM DOSSEG . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX, @DATA MOV DS, AX
  • 107. INSTRUCTIONS FOR CONCLUDING THE PROGRAM MOV AX, 4C00h INT 21h END
  • 108. EXAMPLES OF ASSEMBLY LANGUAGE PROGRAMS • Displaying a character (uppercase ‘A’) on screen. TITLE MYPROG.ASM ; name of the program DOSSEG . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX, @DATA MOV DS, AX MOV AH, 02h ; request display character MOV DL, ‘A’ ; character to display MOV AX, 4C00h ; end INT 21h END
  • 109. Displaying character (lowercase ‘b’) twice on screen. TITLE MYPROG.ASM ; name of the program DOSSEG . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX, @DATA MOV DS, AX MOV AH, 02h ; request display character MOV DL, ‘b’ ; character to display INT 21h ; call interrupt service INT 21h ; call interrupt service MOV AX, 4C00h ; end INT 21h END
  • 110. • Using control characters (0A – Line Feed and 0D – Carriage return) in a screen display. TITLE MYPROG.ASM ; name of the program DOSSEG . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX, @DATA MOV DS, AX MOV AH, 02h ; request display character MOV DL, ‘T’ ; character to display INT 21h ; call interrupt service MOV DL, 0Ah ; line feed character INT 21h ; call interrupt service MOV DL, 0DH ; carriage return character INT 21h ; call interrupt service MOV DL, ‘I’ ; character ‘I’ INT 21h ; call interrupt service MOV DL, 0Ah ; line feed character INT 21h ; call interrupt service MOV DL, 0Dh ;carriage return character INT 21h ; call interrupt service MOV DL, ‘P’ ; character ‘P’ INT 21h ; call interrupt service MOV AX, 4C00h ; end INT 21h END
  • 111. • Displaying different characters (‘A to ‘Z’) using LOOP on the same line. TITLE MYPROG.ASM DOSSEG . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX,@DATA MOV DS,AX MOV CX,001Ah ; setting the number of loops MOV AH,02h ; request display character MOV DL,‘A’ ; character ‘A’ B: INT 21h ; call interrupt service INC DL ; add to 1 to the value of DL LOOP B ; go to label B MOV AX,4C00h ; end INT 21h END
  • 112. MIDTERM Week 7- Instructions And Directives Week 8 – Introduction to Assembly Language Week 9 – Using SK Editor Week 10 – Keyboard handling Week 11 – Screen Handling
  • 113. Instructions And Directives Topics: • Instructions • Categories of Instructions • Directives • Types of Memory Model
  • 114. Objectives To familiarize with the different instructions. To identify the categories of instructions To identify the different directives and their corresponding functions. To identify the different memory modes.
  • 115. Instructions - These are statements that will be translated into machine language and executed by the computer.
  • 116. Examples of instructions MOV ADD SUB MUL DIV INC DEC LOOP CMP
  • 117. Categories of Instructions 1. DATA TRANSFER To move data in the memory and in the CPU registers. Format: Memory to register Register to register Register to stack Stack to register Syntax: Mov Destiny, Source Example: mov ax,bx Note: the list of symbolic instructions are for Intel processor family
  • 118. There are two very important details to note about the mov instruction 1. There is no memory to memory move operation. 2. You cannot move immediate data into a segment register.
  • 119. LDS: Load Data Segment Register LEA: Load Effective Address LES Load Extra Segment Register LODS: Load String LSS: Load stack Segment Register MOV: Move data MOVS: Move String
  • 120. MOVSX: Move with sign-extend MOVZX: Move with Zero-extend STOS: Store string XCHG: Exchange XLAT: Translate
  • 121. 2. ARITHMETIC Syntax: Adc destiny, source Example: Adc bh,bl ADD: add binary numbers ADC: Add with carry DEC: Decrement by 1 INC: Increment by 1 DIV: Unsigned Divide IDIV: Signed (integer) divide MUL: Unsigned multiply IMUL: Signed multiply SUB: Subtract binary values SBB: Subtract with borrow XADD: exchange and add
  • 122. 3. COMPARISON Syntax: CMP destiny, source Example: cmp ax,bx CMP: compare CMPSn: Compare string CMPXCHG: Compare and exchange
  • 123. 4. LOGICAL OPERATIONS Syntax: AND destiny,source Example: And ax,bx AND: Logical AND NOT: Logical NOT OR: Logical OR XOR: Exclusive XOR 5. INPUT/OUTPUT Syntax: OUT destiny,source Example: in ax,dx IN: Input byte or word INSn: Input string OUT: Output byte or word OUTSn: Output string
  • 124. 6. JUMP(conditional) Syntax: ja label Example: ja start JA: Jump if Above JAE: Jump if above/equal JB: Jump if below JBE: Jump if below/equal JE: Jump if Equal JG: Jump if Greater JGE: Jump if Greater/Equal JL: Jump if Less JNE: Jump if Not Equal
  • 125. JNG: Jump if Not Greater JNGE: Jump if Not Greater/Equal JNL: Jump if Not Less JNLE: Jump if Not Less/Equal JNZ: Jump if Not Zero JLE: Jump if Less/Equal JNA: Jump if Not Above JNB: Jump if Not Below JNBE: Jump if Not Below/Equal JZ: Jump if Zero
  • 126. JC: Jump if Carry JCXZ: Jump if CX is Zero JNO: Jump if No Overflow JO: Jump if Overflow JNP: Jump if No Parity JP/JPO: Jump if Parity Odd JPE: Jump if Parity Even JS: Jump if Sign JNS: Jump if No Sign
  • 127. 7. JUMP (Unconditional) CALL: Call a procedure INT: Interrupt IRET: Interrupt Return JMP: Unconditional Jump RET: Return RETN/RETF: Return Near/Return Far
  • 128. 8. LOOPING Syntax: loop label Example: loop a LOOP: Loop until complete LOOPE: Loop While Equal LOOPZ: Loop While Zero LOOPNE: Loop While Not Equal LOOPNZ: Loop While Not Zero
  • 129. 9. STACK INSTRUCTIONS Syntax: pop destiny Example: pop ax POP: Retrieve the content of the Stack PUSH: Store the content of the Stack POPF: Pop Flags off the Stack PUSHF: Push Flags onto Stack
  • 130. Directives - These are statements that give information to the assembler. - Sometimes called pseudo-ops (short term for pseudo operations and pronounced as”su-da- op”). - Unlike instructions, directives are not translated is not machine language but they are necessary for your program to assemble properly.
  • 131. Examples of Directives TITLE DOSSEG .MODEL .STACK .DATA .CODE
  • 132. Most Common Directives 1. TITLE – It creates a title (up to 60 characters) of a source listing. Format: Example: TITLE PROGRAM1.ASM TITLE <TEXT>
  • 133. 2. DOSSEG – It tells the assembler to ignore all other requests and to adopt the DOS segment sequence – stack, data and code. Format: Example: DOSSEG DOSSEG
  • 134. 3. .MODEL – It specifies and initializes the memory model before defining any segment. Format: Example: .MODEL TINY .MODEL SMALL .MODEL MEDIUM .MODEL SMALL <MEMORY-MODEL>
  • 135. Types of Memory Model MEMORY MODEL NO. OF DATA SEGMENT NO. OF CODE SEGMENT Tiny 0 0 Small 1 1 Medium 1 More than 1 Compact More than 1 1 Large More than 1 More than 1
  • 136. 4. .STACK – It defines the size of the stack. The default size is 1,024 bytes which you can overrule. Format: Example: .STACK 0100h .STACK <SIZE>
  • 137. 5. .DATA – It defines and marks the beginning of data segment. Format: Example: .DATA .DATA
  • 138. 6. .CODE – It defines and marks the code segment which consists of a set of instructions. Format: Example: .CODE .CODE
  • 139. 7. END – It is placed at the last line of the source code. Format: Example: END END
  • 140. 8. For Defining Data DIRECTIVE LENGTH DESCRIPTION DB 1 Define Byte DW 2 Define Word DD 4 Define Doubleword DF 6 Define Farword DQ 8 Define Quadword DT 10 Define Tenbytes
  • 141.
  • 142. Introduction to Assembly Language Topics: • Requirements for Coding Assembly language • Reserved Words • Identifiers
  • 143. Objectives • To know the requirements in coding assembly language • To identify the different reserved words. • To know the categories of reserved words • To identify the two types of identifiers. • To know the general guidelines in coding assembly program.
  • 144. Introduction to Assembly Language Using Turbo Assembler
  • 145. Requirements for Coding Assembly language Comment -Is a part of a program that is ignored by the assembler. Though Optional, the use of comments throughout a program can improve its readability and clarity especially in assembly language where the purpose of a set of instructions is often ambiguous. -It begins with a semicolon(;)
  • 146. Ways to include comment • Any Statement whose first non-blank character is a semicolon. Example: ; This program displays Good Day! •At the end of an instruction. Example: MOV AX, 8053h ; initializes the value of ax to 8053h
  • 147. Reserved Words These are words in which the assembler assigns a special meaning and it cannot be used as identifiers. They are reserved for their own purpose to be used only under special condition.
  • 148. Categories of Reserved Words •Instructions •Directives •Operators •Pre-defined Symbols
  • 149. Identifiers An identifier is a user-defined name (Variable) that you apply to an item in your program that you expect to reference.
  • 150. Types of Identifiers •Name – It refers to the address of a data item. Example: x db 0 msg db “Aloha! &” •Label – It refers to the address of an instruction or procedure. Example: mov dl, 41h A: int 21h add dl, 20h int 21h sub dl, 20h loop A
  • 151. Rules in Constructing Valid Identifier •It must be letters (A..Z, a..z), numbers (0-9) &/or special characters like underscore(_), question mark(?) and at sign (@). •* It must always start with a letter. •It must not use reserved words. •It must not exceed to 31 characters. Examples of valid identifiers: neym u2u2 num_1 msg8 Examples of Invalid identifiers: title num-1 4ever F-4
  • 152. Statement An assembly language statement program consists of a set of statements. The two types of statements are instructions and directives.
  • 153. General Guidelines for coding statement •A statement may begin anywhere on the line •Each line can only contain one statement •Unlike C language, assembly is not case sensitive. You can use either upper or lowercase letters. •Take note that statements can have two (2) operands, a single and even none at all. Examples: ADD AX,BX ;uses 2 operands DEC CX ; uses single operand RET ; no operand
  • 154. String -is used for directive data such as person’s name or simply a message. It must end with dollar ($) symbol and defined in double quotation marks (“ ”). DB is the conventional format for defining string of any length. Example: Neym db “Mary’s Internet Café $”
  • 155. Numeric Constant -They are used to define arithmetic values and memory addresses. It is identified with a radix specifier such as d for decimal, b for binary and h for hexadecimal. Example: Msg db “Good day!”, 0ah, 0dh, “$” Is the same with Msg db “Good day!”, 10d, 13d “$” Msg db “Good day!”, 00001010b, 00001101b, “$”
  • 156.
  • 157. Using SideKick Assembling and Linking Procedures Topics: • Using SideKick • Creating Assembly Language • Structure of Assembly language • Assembling and Linking Assembly Language
  • 158. Objectives • To familiarize with the SideKick Environment as text editor. • To know the procedures in invoking Sidekick and quitting from the SideKick window. • To know the procedures in creating and saving assembly program. • To know the procedures in assembling, linking and running assembly program.
  • 159. Using Sidekick as Editor Sidekick - is an editor used for DOS programming like assembly language.
  • 160. Creating Assembly Language Program Step 1: Open the text editor. C:tasm>SK Step2: Type the name of the program with .asm as file extension name. Example: c:program1.asm Step3: You may now start typing your source code.
  • 161. Exiting from the Sidekick Window * Press escape (esc )key to go back to DOS environment.
  • 162. Structure of an Assembly Language Program TITLE PROGRAM1.ASM DOSSEG .MODEL SMALL .STACK .DATA X DB “HELLO THERE!$” .CODE MOV AX, @DATA MOV DS,AX MOV AH,O9H MOV DX,OFFSET X INT 21H MOV AX,4C00H INT 21H END Initializes the program Concludes the program Body of the program
  • 163. Assembling and Linking Procedures Assembling: From the c:tasm> prompt type the following the filename and its extension name then press enter key. Example: c:tasm>program1.asm
  • 164. Linking: After a successful assembly (I.e., no errors encountered), type tlink, press space bar, filename and its extension name then press enter key Example: c:tasm>tlink program1.obj
  • 165. Executing: To run the program, just type the filename only at c:tasm>. Example: c:tasm>program1
  • 166. To recapitulate the overall process: 1. Open the text editor. 2. Save the program. 3. Start keying your program. 4. Exit the editor and go back to DOS environment by pressing the Esc key. 5. Assemble the program by typing tasm filename.asm. 6. If there are no errors, do the next step otherwise, repeat steps 1-5 and rectify the program. 7. Link the object file by typing tlink filename.obj & press enter key. 8. Type filename and press enter key to run the program.
  • 167.
  • 168. KEYBOARD HANDLING Topics: Interrupt and Service Character Output Character Input String Display String Input
  • 169. Objectives • To identify the function/service number used to input/output character. • To identify the function/service number used to input/output string. • To identify the corresponding interrupt used in character and string input/output.
  • 170. Interrupt – execute commands Service – set the command Interrupt and Service
  • 171. Character Output Int 21h / 02 This function display one character on the screen. AH = 02h DL = holds the character to display on the screen.
  • 172. Example: . MODEL SMALL . STACK 0100h . DATA . CODE MOV AX, @DATA MOV DS, AX MOV AH, 02h ; request display character MOV DL, ‘j’ ; character to display INT 21h ; call interrupt service INT 21h ; call interrupt service MOV AX, 4C00h ; end INT 21h END
  • 173. Character Input Int 21h / 1 – Keyboard input This function waits for you to type a character on the keyboard. It echoes the character to the screen and returns the ASCII character in the AL register. AH = 01 AL = character read from the keyboard
  • 174. Example: .model small .stack .data .code mov ah, 01h ; request for character input int 21h
  • 175. Character Input Int 21h / 7 – keyboard input without echo This function reads a character from a keyboard but doesn’t display the character on the screen and wait for control break. AL = character read from the keyboard
  • 176. Character Input Int 21h / 8 – keyboard input without echo This function works the same way with service 7 but do not respond to control break. AL = character read from the keyboard
  • 177. Example:.MODEL SMALL .STACK 0100H .DATA MSG DB “INPUT ANY CHARACTER: $” MSG2 DB 0AH, 0DH, “The character you type is: $” x db 0 .CODE MOV AX,@DATA MOV DS, AX MOV AH,09H MOV DX,OFFSET MSG1 INT 21H MOV AH,01H ;REQUEST FOR CHARACTER INPUT INT 21H MOV X,AL MOV AH,09H MOV DX,OFFSET MSG2 INT 21H MOV AH,02H MOV DL,X INT 21H MOV AX,4C00H INT 21H
  • 178. String Display Int 21h / 09 This function displays the string pointed by the DS:DX pair of registers. The end of the string should be marked with the $ sign. DS:DX points to address of the string
  • 179. String Display Int 21h / 09h Display string in the data area followed by a dollar sign ($ or 24h) delimiter, which the operation uses to end the display. Example: Nick_name db “Your nickname: $“ ;display string
  • 180. Example fragment of a program MOV AH,09H ;request display LEA DX, NICK_NAME ;load address of prompt INT 21H ;call interrupt service
  • 181. String Input Int 21h / 0A This function reads the string from the keyboard. DS:DX points to address of the string
  • 182. Example: . MODEL SMALL . STACK 0100h . DATA NEYM DB 08h, ?, 08h DUP (“$”) Q DB “What is your name? $” A1 DB 0Ah, 0Dh, “What a nice name ! $” A2 db 0Ah, 0Dh, “I’m glad to meet you ! $” . CODE MOV AX, @DATA MOV DS, AX MOV AH, 09h MOV DX, OFFSET Q MOV AH, 0Ah ; request for string input MOV DX, OFFSET NEYM ; load address INT 21h MOV AH, 09h MOV DX, OFFSET A1 INT 21h MOV AH, 09h MOV DX, OFFSET NEYM+2 INT 21h MOV DX, OFFSET A2 INT 21h MOV AX, 4C00h INT 21h END
  • 183. DISPLAYING THE INPUT STRING The following instructions display the input string starting at the third memory address. MOV AH, 09h ; request for string output MOV DX, OFFSET X+2 ; LOAD ADDRESS INT 21h
  • 184. Sample program that demonstrates string and displays it again on screen. . MODEL SMALL . STACK 0100h . DATA NEYM DB 08h, ?, 08h DUP (“$”) Q DB “What is your name? $” A1 DB 0Ah, 0Dh, “What a nice name ! $” A2 db 0Ah, 0Dh, “I’m glad to meet you ! $” . CODE MOV AX, @DATA MOV DS, AX MOV AH, 09h MOV DX, OFFSET Q MOV AH, 0Ah ; request for string input MOV DX, OFFSET NEYM ; load address INT 21h MOV AH, 09h MOV DX, OFFSET A1 INT 21h MOV AH, 09h MOV DX, OFFSET NEYM+2 INT 21h MOV DX, OFFSET A2 INT 21h MOV AX, 4C00h INT 21h END
  • 185.
  • 186. Screen Handling Topics: • The Monitor • GRAPHICS
  • 187. Objectives • To identify the instructions and directives used for screen handling applications • To create an assembly program with the application of graphics.
  • 188. THE MONITOR • A typical video screen has eighty (80) columns numbered from 0 to 79 and twenty five (25) rows numbered from o to 24. The columns and rows provide a grid of addressable locations at any one of which the cursor can be set. The table below shows the examples of a cursor locations
  • 189. Screen Location COLUMN ROW COLUMN ROW In hexadecimal value In hexadecimal value Upper Left Corner 0 0 00H 00H Upper Right Corner 79 0 4FH 00H Center of Screen 40 12 28H 0CH Lower Left Corner 0 24 00H 18H Lower Right Corner 79 24 4FH 18H Screen Features
  • 190. Clearing the Screen in Assembly Approach Int 10h / 06h Handles the process of clearing the screen and scrolling. AH = Function in 06H AL = number of lines to scroll, or 00H for the full screen BH = attribute value (color blinking etc.) CX = starting row column DX = ending row column
  • 191. sample code shows how to create the clear screen: MOV AX,0600h ;AH=06h (Scroll), AL=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
  • 192. SETTING THE CURSOR POSITION Int 10h / 02 Used to set the cursor position. AH = 02 MOV AH, 02h ; request to set the cursor position MOV BH, 002h ; page number 0 MOV DH, 0Ah ; Row = 10 in decimal MOV DL, 08h ; Column = 8 in decimal INT 10h ; call interrupt service
  • 194. DISPLAYING THE STRING ‘FLOWERS’ AT THE CENTER OF THE SCREEN .MODEL SMALL .STACK 0100h .DATA A DB “FLOWERS$” .CODE MOV AX,@DATA MOV DS,AX MOV AX,0600h ; AH=00h (Scroll0, AL=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 MOV AH,02h ; request to set the cursor position MOV BH,00h ; page number 0 MOV DH,0Ch ; Row = 12 in decimal MOV DL,24h ; Column = 36 in decimal INT 10h ; Call interrupt service MOV AH,09H ; request display string LEA DX,A ; load address of the string MOV AX, 4C00h INT 21h END
  • 195. Graphics TEXT AND BACKGROUND COLORS BACKGROUND COLOR TEXT COLOR HEX CODE MEANING BL R G B I R G B 0 0 1 0 1 0 0 0 28 Green Background Color Gray Text Color 1 0 1 0 1 0 0 0 0A8 Green Background Color Gray Black Color Blinking 0 1 1 0 0 0 0 1 61 Brown Background Color Blue Text Color 1 1 1 0 0 0 0 1 0E1 Brown Background Color Blue Text Color Blinking
  • 196. DESIGNING PROGRAMS USING PROCEDURE Procedures make it possible to break a large program down into smaller pieces so that each piece can be shown to work correctly without the reference to any of the others.
  • 197. DEFINING A PROCEDURE Every procedure is defined using PROC and ENDP directives. Since these are directives, they don’t generate machine language instructions; rather, PROC and ENDP are directions to the assembler, making the beginning and end of a procedure. In assembly, the first declared procedure in the program is considered the major calling procedure.
  • 198. Format & Example • Format: • • <procedure-name> PROC • <instruction-1> • <instruction-2> • … • <instruction-n> • <procedure-name> ENDP • Example: • • MAIN PROC • CALL P1 • CALL P2 • CALL QUITPROGRAM • MAIN ENDP
  • 199. CALLING PROCEDURE To call a procedure Format: CALL <procedure-name>
  • 200.
  • 201. FINALS Week 13 – File and Disk handling Week 14 – Sample Programs in Assembly Language Week 15 – Math Operation Week 16 – In-line Assembly Week 17 – Case Study
  • 202. FILE AND DISK HANDLING Topics: •Common DOS File Handle Services •File Attributes •Modes of Accessing Files
  • 203. Objectives: • To identify and familiarize with the different services for file and disk handling. • To create a program using the different services in file and disk handling. • To identify the different file attributes • To apply the different modes of accessing files.
  • 204. Common DOS File Handle Services
  • 205. INT 21H / 39H Create Subdirectory This service creates a subdirectory as does the system command MKDIR. To use it, load DX with the address of an ASCIIZ string containing the drive and directory pathname. AH = 39H DS:DX = points to ASCIIZ If CX = 1, AX has error
  • 206. Example fragment of a program: ASCstrg DB ‘n:pathname’, 00H ;ASCIIZ string … MOV AH,39H ;request create subdirectory LEA DX,ASCstrg ;Address of ASCIIZ string (DS:DX) INT 21H
  • 207. Remove Subdirectory This service deletes a subdirectory, just as does the system command RMDIR. Note that you cannot delete the current (active) directory or a subdirectory containing files. Load DX with the address of an ASCIIZ string containing the drive and directory pathname. AH = 3AH DS:DX = points to ASCIIZ string IF CX = 1, AX has error INT 21H / 3AH
  • 208. Example fragment of a program: ASCstrg DB ‘n:pathname’,00H ;ASCIIZ string … MOV AH,3AH ;request delete subdirectory LEA DX,ASCStrg ;address of ASCIIZ (DS:DX) INT 21H ;call interrupt service
  • 209. INT 21H / 56H Rename File or Directory This service name a file or directory from within a program. Load DX with the address of an ASCIIZ string containing the old drive, path and name of the file or directory to be renamed. Load DI (combined as ES:DI) with the address of an ASCIIZ string containing the new drive, path and name, with no wild cards.
  • 210. Drive numbers, if used, must be the same in both strings. Because the paths need not be the same, the operation can both rename a file and move it to another directory on the same drive.
  • 211. Example fragment of a program: Oldstring db ‘n:oldpatholdname’,00h Newstring db ‘n:newpath]newname’,00h … MOV AH,56H ;request rename file/directory LEA DX,Oldstring ;DS:DX LEA DI,Newstring ;ES:DI
  • 212. INT 21H / 5BH Create a new File This service creates a file only if the named file does not already exist; otherwise it is identical to function 3CH (create file). You could use function 5BH whenever you don’t want to overwrite an existing file.
  • 213. INT 21H / 3CH Create File AH = 3CH DS:DX = points to ASCIIZ string CX = attribute
  • 214. File Attributes BIT ATTRIBUTE 0 Read only file 1 Hidden file 2 System file 3 Volume label 4 Subdirectory 5 Archive file
  • 215. INT 21H / 43H Get/Set File Attribute You can use this operation either to get or set a file attribute in the directory. This operation requires the address of an ASCIIZ string containing the drive, path and filename for the requested file. (Or use the default directory if no path is given.)
  • 216. Example fragment of a program: ASCstrg db ‘n:pathname’,00H ;ASCIIZ string … MOV AH,43H ;request MOV AL,00H ;get attribute LEA DX,ASCstrg ;ASCIIZ string (DS:DX) INT 21H ;call interrupt service
  • 217. INT 21H / 3BH Change Directory This service changes directory. AH = 3BH DS:DX = points to ASCIIZ string If CX = 1, AX has error
  • 218. Modes for Accessing Files Access mode Means 0 Read Only 1 Write Only 2 Both Read and Write
  • 219. INT 21H / 3DH Open File This function opens a file. AH = 3DH DS:DX = points to ASCIIZ string AL = MODE
  • 220. INT 21H / 3EH Close File This service closes a file. AH = 3EH BX = file handle If CX = 1, AX has error
  • 221. INT 21H / 41H Delete File This service deletes a file (but not read- only) from within a program. Load the address in DX of an ASCIIZ string containing the device path and filename, with no wild cards references.
  • 222. Example fragment of a program: ASCstrg db ‘n:pathname’,00H ;ASCIIZ string … MOV AH,41H ;request delete file LEA DX,ASCSTRG ;address of ASCIIZ string (DS:DX) INT 21H ;call interrupt service
  • 223. Sample Programs In Assembly Language Topic: • Designing programs using procedure • Basic Stack Instruction • Loop Instruction
  • 224. Objectives: • Create an assembly program with procedures. • Create an assembly program using stack instruction. • Create an assembly program using loop instruction.
  • 225. DESIGNING PROGRAMS USING PROCEDURE • DEFINING A PROCEDURE Every procedure is defined using PROC and ENDP directives. Since these are directives, they don’t generate machine language instructions; rather, PROC and ENDP are directions to the assembler, making the beginning and end of a procedure. In assembly, the first declared procedure in the program is considered the major calling procedure.
  • 227. CALLING PROCEDURE To call a procedure Format: CALL <procedure-name>
  • 228. Example: .model small .code org 100h start: jmp main x db “assembly$” y db “language$” z db “program$” main proc near mov dx,offset x call proc1 call proc2 mov dx,offset y call proc 1 call proc2 mov dx,offset z call proc1 call proc2 main endp
  • 229. proc2 proc near mov ah,2 mov dl,13 int 21h mov dl,10 int 21h ret proc2 endp proc1 proc near mov ah,9 int 21h ret proc1 endp end start
  • 230. Basic Stack Instruction Push Instruction puts/places data onto the stack segment Pop Instruction takes out data from the stack
  • 231. Format: • push reg16 • pop reg16 • push reg32 (3) • pop reg32 (3) • push segreg • pop segreg (except CS) push memory • pop memory
  • 232. • The first two instructions push and pop a 16 bit general purpose register. This is a compact (one byte) version designed specifically for registers
  • 233. • The second pair of instructions push or pop an 80386 32 bit general purpose register.
  • 234. • The third pair of push/pop instructions let you push or pop an 80x86 segment register.
  • 235. • The fourth pair of push/pop instructions allow you to push or pop the contents of a memory location.
  • 236. Example: .model small .code org 100h start: mov cx,5 x: mov ah,1 int 21h add al,20h push ax loop x
  • 237. mov ah,2 mov dl,13 int 21h mov dl,10 int 21h mov cx, 5 y: pop dx int 21h loop y int 20h end start
  • 238. Loop Instruction Loop allows a part of the program to be repeated for several times, the number of loops depend on the value of the CX register. - each time the loop is executed, CX is decremented and the looping stops when CX becomes zero.
  • 239. Format: LOOP label Example: LOOP start This will cause the program flow to go to the label start for CX times.
  • 240. Example: .model small .code org 100h start:mov cx,20 mov ah,2 mov dl, ‘j’ z: int 21h loop z end start
  • 241.
  • 243. Objectives: • To create a program using addition, subtraction, multiplication and division of Binary Coded Decimal. • To create a program that converts the addition, subtraction of ASCII codes to BCD. • To identify the instructions and directives for addition, subtraction of BCD.
  • 244. BCD • binary coded decimals Binary coded decimal (BCD) is a method for implementing lossless decimal arithmetic (including decimal fractions) on a binary computer. The most obvious uses involve money amounts where round-off error from using binary approximations is unacceptable. Some early computers used BCD exclusively. •
  • 245. • Decimal digits (0-9) can be encoded in a nibble (half a byte), with some left over bit patterns (hexadecimal A-F). In BCD operations, the processor performs ordinary binary computations, then adjusts the result to conform to BCD. • For example, if you add the binary number 5 (bit pattern 0101) to binary number 6 (bit pattern 0110), you get the binary result of 11 (bit pattern 1011, or hexadecimal B). With BCD arithmetic, the processor would adjust the result to make it into a valid BCD result (which in this case would be bit pattern 0001 0001).
  • 246. • BCD arithmetic includes BCD addition, BCD subtraction, BCD multiplication, BCD division, and BCD negate. The Intel 80x86 series uses a two step approach for BCD arithmetic. Instead of having separate BCD instructions, the normal binary addition and subtraction instructions are used, then hardware instructions are used to adjust the results to correct BCD results. • There are instructions for both packed and unpacked adjustments.
  • 247. • The advantage of this approach is greater flexibility (more addressing modes and choices of arithmetic operations because of the use of regular binary integer instructions in the first step). • The disadvantage of this approach is that it is slower and takes more memory.
  • 248. ASCII • American Standard Character Information Interchange. • Refer to ASCII Table
  • 249. Adding ASCII Numbers Consider the effect of the following three examples of adding ASCII numbers: Ex. 1 35H Ex.2 38H Ex.3 39H +32H 34H +39H Total 67H 6CH 72H
  • 250. Example 1. The sum of 35h and 32h is 67h. AAA checks the rightmost digit (7). Because it is not between A and F, nor is the AF flag set, AAA clears the leftmost digit (6) to 0.
  • 251. Example 2. The sum of 38H and 34 H is 6CH. Because the right most digit (C) is between A and F, AAA performs the following: AH AL 00 0C Adds 6 to AL 00 72 Adds 1 to H 01 72 Clears leftmost digit of AL 01 02 (sum = 12)
  • 252. Example 3. The sum of 39H and 39H is 72H. Although the rightmost digit (2) is not between A and F, the AF flag is set because of the carry into the tens position. AAA performs the following: AH AL 00 72 Adds 6 to AL 00 78 Adds 1 to AH 01 78 Clears leftmost digit of AL 01 08 (sum = 18)
  • 253. Subtracting ASCII NUMBERS Example 1. ASCIIvalue1 contains 39h and ASCII value2 contains 39h. Subtracts ASCIIvalue2 (35h) from ASCIIvalue1 (39h). AAS does not need to make an adjustment because the rightmost hex digit is less than the hex A. AX AF CF MOV AL,ASCVALUE1 ; 0039 SUB AL,ASCVALUE2 ; 0004 0 0 AAS ; 0004 0 0 OR AL,30h ; 0034
  • 254. Example 2. Subtracts ASCIIvalue1 (39h) from ASCII value2 (35h). Because the rightmost digit of the result is hex C, AAS subtracts 6 from AL, subtracts 1 from AH, and sets the AF and CF flags: AX AF CF MOV AL,ASCVALUE2 ; 0035 SUB AL,ASCVALUE1 ; 00FC 1 1 AAS ; FFO6 1 1 The answer, which should be -4, is FF06h, its ten’s complement; that is, decimal -10 + 6 = -4.
  • 255. Multiplying ASCII Numbers INSTRUCTION COMMENT AX CL . . . ; Initial values 0035 39 AND CL, 0FH ; Convert CL to 09 0035 09 AND AL, 0FH ; Convert CL to 05 0005 09 MUL CL ; Multiply AL by CL 002D 09 AAM ; Convert AX to unpacked BCD OR AX 3030H ; Convert AX to ASCII 3435
  • 256. Dividing ASCII Numbers INSTRUCTION COMMENT AX CL . . . ; Initial values 3238 37 AND CL,0FH ; Convert to unpacked BCD 3238 07 AND AX,0FH0FH ; Convert to unpacked BCD 0208 AAD ; Convert to binary 00IC DIV CL ; Divide by 7 0004
  • 257. CONVERTING BINARY DATA TO ASCII FORMAT • The following example converts binary number 0DF1H to ASCII format: ASCVALUE DB 4 DUP (‘ ‘) ; Data Items BINVALUE DW 0DF1H . . . MOV CX, 0010 ; Division factor LEA SI, ASCVALUE ;Address of SCVALUE MOV AX, BINALUE ; Get binary amount
  • 258. L20: CMP AX,CX ; Value < 10? JB L30 ; yes, exit XOR DX,DX ; Clear upper quotient DIV CX ; Divided by 10 OR DL,30H MOV [SI],DL ; Store ASCII character DEC SI JMP L20 L30: OR AL,30H ;Store last quotient MOV [SI], AL ; as ASCII character
  • 259. C20: mov al,[SI] ;get a byte Shr al,04 ;shift off right hex digit Lea bx,xlatab ;set table address Xlat ; translate hex Stosb ;store AL in DISPAREA Mov al,[SI] ;get other half of byte And al,0fh ;clear left hex digit Xlat ;translate hex Stosb ;store AL in DISPAREA Inc SI ; incr address of IOBUFFER Lea bx,IOBUFFER+512 ; Cmp SI,BX ;end of IOBUFFER? Jb c20 ;if no, repeat Lea bp,disparea ;if yes, display Mov cx,1024 ;hex characters Call D10DISPLAY ret C10CONVRT endp
  • 260. ; display data: ; - - - - - - - - - ;uses AX, BX, DX D10DISPLAY proc near ;BP, CX set on entry MOV AX,1301 ;request display MOV BX,0016H ;page:attribute MOV DX,0500H ;row:column RET D10DISPLAY end p End A10MAIN
  • 261.
  • 262. In-Line Assembly Topic: • Comparison of C Language to Assembly
  • 263. Objective: • To construct a program with the integration of Pascal and C language programming.
  • 264. Comparison of C Language To Assembly Language
  • 265. If..Else Construct A conditional statement of C language in the form: If <condition> { <statement-1>; <statement-2>; . . . <statement-n>; } Else { <statement-1>; <statement-2>; . . . <statement-n>; }
  • 266. Can be implemented by assembly language of the form: <cmp instruction> <conditional jump instruction> <label-1> <instruction-1> <instruction-2> … <instruction-n> <jump instruction> <label-2>
  • 267. Comparison C language Assembly language If (ax == 0) { cx = cx – ax; ax = ax + 1; } Else { Cx = cx – 8; } CMP AX,0000H JNZ ACTION1 SUB CX,AX INC AX JMP NEXT ACTION1: SUB CX,0008H NEXT:
  • 268. Do..While Construct A do..while loop similar to C language: do { <statement-1>; <<statement-2>; … <statement-n>; } while <condition>;
  • 269. Can be implemented by assembly in the form: <label>: <instruction-1> <instruction-2> … <instruction-n> <cmp instruction> <conditional jump instruction> <label>
  • 270. Comparison C language Assembly language ax = 5; do { ax = ax – 1; bx = bx + 1; } while (ax >= 0); MOV AX,0005H HERE: DEC AX INC BX CMP AX JNZ HERE
  • 271. While Construct Similarly, C language while loop: While <condition> { <statement-1>; <statement-2>; … <statement-n>; }
  • 272. Is roughly equivalent to the assembly language structure: <label-1>: <cmp instruction> <conditional jump instruction> <label> <instruction-1> <instruction-2> . . . <instruction-n> jmp <label-1> <label-2>: <instruction-1> <instruction-2> . . . <instruction-n>
  • 273. Comparison C language Assembly language while (ax <= 10) { ax = ax + bx; bx = bx + 1; } START: CMP AX,000AH JGE NEXT ADD AX,BX INC BX JMP START NEXT: ADD CX,AX
  • 274.
  • 275. Final Case Study Design a problem that will utilize any of the constructs if-else, do- while and while. Please don’t forget to check the complexity and eventual completeness of your output.
  • 276. Objective: • To develop programs that apply the whole concepts of assembly programming.
  • 277.
  • 279. ENDEND