You are on page 1of 11

C:\Users\zahid\Desktop\x86\notes.

docx Friday, August 21, 2020 11:58 PM

#################################################
###### Chapter - 1, Microcomputer Systems #######
#################################################

# Components
1. RAM (Random Access Memory)
2. ROM (Read Only Memory)
3. Buses
=> Data Bus
=> Address Bus
=> Control Bus
4. CPU (Central Processing Unit)
=> Execution Unit (EU)
=> ALU (Arithmetic and Logic Unit)
=> Registers
=> AX, BX, CX, DX, BP, SP, SI, DI, Flags
=> Bus Interface Unit (BIU)
=> Registers
=> DS, ES , SS, IP
5. I/O Ports
=> Serial Ports
=> Parallel Ports

# NOTES
1. Instructions, Instruction Set
2. Opcode
3. Fetch Execution Cycle
4. Assembler
5. Compiler

##################################################################
###### Chapter - 2, Representation of Numbers and Characters #####
##################################################################

1. Binary
2. Octal
3. Decimal
4. Hexadecimal
-1-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

5. Binary Arithmetic
6. Unsigned Integers
7. Signed Integers
8. One's Complement
9. Two's Complement
10. ASCII Codes

###########################################################
###### Chapter - 3, Organization of Intel Processors ######
###########################################################

# Registers (14)
1. Data Registers (4)
=>AX (AH, AL) - Accumulator Register
=>BX (BH, BL) - Base Register
=>CX (CH, CL) - Count Register
=>DX (DH, DL) - Data Register
2. Address Registers (9)
# Segment Registers (4) // Program Segments
=>CS - Code Segment
=>DS - Data Segment
=>SS - Stack Segment
=>ES - Extra Segment // for second data segment
# Pointer Registers (3)
=>SP - Stack Pointer
=>BP - Base Pointer
=>IP - Instruction Pointer
# Index Registers (2)
=>SI - Source Index
=>DI - Destination Index
3. Status/Flag Register (1)
- Status of Microprocessor
# Flags
=> Status Flags (ZF)
=> Control Flags (IF)

# NOTES
1 byte = 8 bits
-2-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

1 word = 2 bytes = 16 bits = 1h


1 paragraph = 16 bytes = 256 bits = 10h

# Memory Segment
def: 2^16 (64K) consecutive memory bytes

# physical address = segment x 10h + offset

=> Logical Address (segment:offset)


A4FBh:4872h
=> Physical Address
A4FB0h + 4872h = A9822h

# OPERATING SYSTEM (OS)

# Purpose of OS
1. Reading and executing commands typed by the user
2. Performing I/0 operations
3. Generating error messages
4. Managing memory and other resources

# Disk Operating System (DOS)


# Basic Input Output System (BIOS)
# Interrupt Vector - Addresses of BIOS routines

##################################################################
##
###### Chapter - 4, Introduction to Intel PC Assembly Language
#####
##################################################################
##

# Statements
=> Instruction
=> Assembler Directive

# Statement Syntax
-3-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

[name] [operations] [operand(s)] [comment]


eg. START: MOV CX,8 ;initialize counter // Instruction
eg. MAIN PROC // Assembler Directive

# Data-Defining Pseudo-ops
1. DB - Define byte
2. DW - Define Word
3. DD - Define doubleword
4. DQ - Define quadword
5. DT - Define tenbytes

# Few Basic Instructions


MOV, XCHG, ADD, SUB, INC, DEC, NEG

1. MOV destination, source


eg. MOV AX,BX

2.XCHG destination, source


eg. XCHG AH, BL

3.ADD destination, source


eg. ADD WORD1, AX
eg. ADD BYTE1, AL
eg. ADD BL, 5

4.SUB destination, source


eg. SUB AX, DX

5.INC destination
eg. INC WORD1

6.DEC destination
eg. DEC BYTE1

7.NEG destination
eg. NEG BX

# Few Basic Statement Translation


-4-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

eg. B=A
MOV AX, A ;move A inot AX
MOV B, AX ;and then into B

eg. A=5-A
MOV AX, 5 ;put 5 in AX
SUB AX, A ;AX contains 5-A
MOV A, AX ;put it in A

eg. A=5-A
NEG A ;A=-A
ADD A, 5 ;A=5-A

eg. A=B-2xA
MOV AX, B ;AX has B
SUB AX, A ;AX has B-A
SUB AX, A ;AX has B-2xA
MOV A, AX ;move results to A

# # # Memory Model
# Syntax: .MODEL [memory_model]
memory_models: SMALL, MEDIUM, COMPACT, LARGE, HUGE

.MODEL SMALL
- Code in one Segment
- Data in one Segment

.MODEL MEDIUM
- Code in more than one Segment
- Data in one Segment

.MODEL COMPACT
- Code in one Segment
- Data in more than one Segment

.MODEL LARGE
- Code in more than one Segment
- Data in more than one Segment
- No array larger than 64k bytes
-5-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

.MODEL HUGE
- Code in more than one Segment
- Data in more than one Segment
- Arrays may be larger than 64k bytes

# # # Data Segment
- Contains all variables definition
- Constants definition

eg. .DATA
WORD1 DW 2
WORD2 DW 5
MSG DB 'This is a message'
MASK EQU 10010010B

# # # Stack Segment
- Reserve a block of memory in stack

# Syntax: .STACK size


eg. .STACK 100H (100 bytes)

# # # Code Segment
- Contains program's instructions
- Procedures declared in Code Segment

# Syntax: .CODE name


# Procedure Definition:
name PROC
;body of the procedure
name ENDP
eg. .CODE
MAIN PROC
;main procedure instructions
MAIN ENDP
;other procedures go here

# EXAMPLE - 0
-6-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

.MODEL SMALL
.STACK 100H
.DATA
;data definitions go here
.CODE
MAIN PROC
;instructions go here
MAIN ENDP
;other procedures go here
END MAIN

# # # Input and Output Instructions


# Two Instructions:
1. IN
2. OUT
# Two I/O Service Routines:
1. BIOS routines
2. DOS routines

# INT(Interrupt) Instruction
- Invokes a DOS or BIOS routine
# Syntax: INT interrupt_number
eg. INT 16h
- Invokes BIOS routine to perform keyboard input
eg. INT 21h
- Invokes DOS functions
# function specified by placing function number in AH
# function numbers
1 - single-key-input
2 - single-character-input
3 - character-string-output

# Function 1 - single-key-input
Input: AH = 1
Output: AL = ASCII code if any character key pressed
= 0 if non-character key pressed

eg. MOV AH, 1 ;input key function


-7-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

INT 21h ;ASCII code in AL

# Function 2 - Display a character or execute a control function


Input: AH = 2
DL = ASCII code of the display character or control
character
Output: AL = ASCII code of the display character or control
character

eg. MOV AH, 2 ;display character function


MOV DL, '?' ;character is '?'
INT 21H ;display character

# Control Functions
7 (07H) => BEL => Beep (Sounds a tone)
8 (08H) => BS => Backspace
9 (09H) => HT => Tab
A (0AH) => LF => Line feed (newline)
D (0DH) => CR => Carriage Return (start of current line)

# 21h casuses the control function to be performed

# EXAMPLE - 01
TITLE PGM_1: ECHO PROGRAM
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
;main prompt
MOV AH, 2 ;display character function
MOV DL, '?' ;character is '?'
INT 21H ;display it

;input a character
MOV AH, 1 ;read character function
INT 21H ;character in AL
MOV BL, AL ;save it in BL

-8-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

;go to a new line


MOV AH, 2 ;display character function
MOV DL, 0DH ;carriage return
INT 21H ;excute carriage return
MOV DL, 0AH ;line feed
INT 21H ;execute line feed

;display character
MOV DL, BL ;retrieve character
INT 21H ;and display it

;return to DOS
MOV AH, 4CH ;DOS exit funcation
INT 21H ;exit to DOS

;main end
MAIN ENDP
END MAIN

# Notes:
- When a program terminates, it should return control to DOS.
This can be accomplished by excuting INT 21h, funcation 4CH

# Steps for Creating and Running a Programs


Step - 1: Using a text editor to create a source program using
.asm extensuion
Step - 2: Using an Asssembler to create machine language object
file
Step - 3: Using the LINK program to link one or more object file
Step - 4: Execute the run file

# Tools: Assembler, Linker

# Workflow:
Editor => .ASM File => Assembler => .OBJ File => Linker =>
.EXE File

# Microsoft Macro Assembler (MASM)

-9-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

-10-
C:\Users\zahid\Desktop\x86\notes.docx Friday, August 21, 2020 11:58 PM

-11-

You might also like