Cracking the USMLE!! MUHAMMAD ALI KHAN M.D. FARAZ KHAN LUNI M.D. ISRA’A KHAN M.D. ISRA’A KHAN M.D.
Slide 1 of 53 Ver. 1.0 Programming in C ASSEMBLY LANGUAGE LECTURE 01-05 BASIC INFORMATION By SHERY...
Transcript of Slide 1 of 53 Ver. 1.0 Programming in C ASSEMBLY LANGUAGE LECTURE 01-05 BASIC INFORMATION By SHERY...
Slide 1 of 53Ver. 1.0
Programming in C
ASSEMBLY LANGUAGE
LECTURE 01-05
BASIC INFORMATION
By
SHERY KHAN
10:00 to 11:30
Slide 2 of 53Ver. 1.0
Programming in C
In this session, you will learn to:Identify the benefits and features of Assembly language
What is Assembler
How to use Assembler
Identify the structure of Assembly functions
Binary And Hexadecimal Discussion
Short History of Assembly language(iApx88 Hierarchy)
Detail Registers and Categories of Register
Register Functionalities
Sample Program
Data Declaration
Sample Program
………………………….
Objectives
Slide 3 of 53Ver. 1.0
Programming in C
What is Assembly Language
Assembly Language is a Machine Specific Programming Language with one to one Correspondence b/w its Statement and computer native Machine Language
There are many Different Types of Assembly Language each specific to processor or processor Family this is because the instruction in Assembly language are Designed to match a Computer Machine Instructions Set and Hardware Architecture
IBM PC assembly Language refer to instruction recognized by num of Different micro processors in Intel family
8086,8088,80186,80386,80486, and Pentium
Slide 4 of 53Ver. 1.0
Programming in C
AssemblerAssembler is a program that Convert source code program from
Assemble Language into Machine Language
The Assembler can optionally generate a source listing file with line number ,memory addresses ,source data code statement ,and cross reference listing of Symbol and variable used in program
Linker
A companion program called linker combine individual files created bt assembler with Single Executable File: DEBUGGER:
Third Program called Debugger provides away for programmer to trace execution of program and Examine the Content of memory
What is Assembler ? & TOOLS ?
Slide 5 of 53Ver. 1.0
Programming in C
Steps for Understanding to develop a Context:
Step 1:
Write a program name with ex01.asm Save it in the Assemble folder in let example D’derive
Step 2: then go to the Run write “cmd “ a Dos is Open
Following command is on Dos you will See
C:\document setting \window Xp >
Now write the in the front of this Command “d;”
SEE THE Detail with synapshots:
How to use Assembler ? & TOOLS ?
Slide 6 of 53Ver. 1.0
Programming in C
First Look Simple Dos is Open
How to use Assembler ? & TOOLS ?
Slide 7 of 53Ver. 1.0
Programming in C
How to use Assembler ? & TOOLS ?
I can Give him a Directory Were I Save the Assembly Folder Like D drive in Second Pic I can write cd which mean Display Change in Directory and Give Him A Folder Name”
Slide 8 of 53Ver. 1.0
Programming in C
How to use Assembler ? & TOOLS ?
Now write the Command “nasm ex01.asm-o ex01.com-l ex01.lst after this Execution a Lst and COM File is Generated Here Pictorial View
Slide 9 of 53Ver. 1.0
Programming in C
How to use Assembler ? & TOOLS ?
Now Edit command is used to Write Some Instruction or rewrite the File
So for this purpose we use “Edit ex01.asm “
Slide 10 of 53Ver. 1.0
Programming in C
How to use Assembler ? & TOOLS ?
For Execution of COM file we Must Load it in the Debugger the Last Step is And Command is
afd Ex01.COM
Pictorial View Here
Slide 11 of 53Ver. 1.0
Programming in C
Identify the structure of Assembly functions :
Why we Learn Assembly Language???
If our Software want to direct communication with the Pc OS may be Necessary or Computer Game
Application might have to directly Access the Video Controller or Sound Card So in Assembly Language a routine is Written for Speedy Communication with
Hardware.like Utility Softwares
Why It is Called Low level Language ??
Because it is Close to Machine Language.
Weakness that its programs are not recompiled & Executed on different Computer.
Slide 12 of 53Ver. 1.0
Programming in C
Number System Disscussion
System Base Possible Digits
Binary 2 0,1
octal 8 0,1,2,3,4,5,6,7
Decimal 10 0-9
Hexa Decimal
16 0-9 A,B,C,D,E,F
Slide 13 of 53Ver. 1.0
Programming in C
Number System Disscussion
Assembly Debugger work with Hexadecimal System which take 4 bits
Decimal To Binary to Hexdecimal
Here Example
Decimal Binary Hexa Decimal
65 0100 0001 41
41
Slide 14 of 53Ver. 1.0
Programming in C
Number System Disscussion
Convert 3BA4 to Decimal
3*16 pow 3 +
B*16 pow 2 +
A*16 pow 1 +
4*16 pow 0 +
Decimal Result is 15268
Above A=10 B=11
Slide 15 of 53Ver. 1.0
Programming in C
Signed Number:
A Signed Byte Used Only 7 Bits were 0 indicate +ve and 1 indicate –ve
Unsigned Number:
A Unsigned Byte used 8 bits largest value is 255
Bit: Each Digit in a Binary Num System Is Bit
Byte: Eight Bits together Make A byte
Word: 16 Bits Are called Word which is 2 byte long
Double Word: 32 bits are called DW
Quad Word : 64 bits Are called QW
Calculation Formula: (2 pow b -1) b indicate bits.
Number System Disscussion
Slide 16 of 53Ver. 1.0
Programming in C
CPU DESIGN SIMPLIFIED VIEW
Data BUS
Address Register
Address BUS
Data RegisterMemory
Cpu
ALU
CPU:
FETCH
DECODE
Execute
Slide 17 of 53Ver. 1.0
Programming in C
Adress ,Data And Control Bus:
Adress Bus:is a Uni directional Bus and Adress Always travel from Processor to Memory because memory cannot predict which element processor at a particular time need.
Processor Memory
Data Bus:
Data Moves from processor to memory and Memory to Processor So Data Bus is
Bi directional
Memory To Processor (Read operation)
Processor to Memory (Write operation)
Control Bus :Also Bi directional
Slide 18 of 53Ver. 1.0
Programming in C
REGISTERs:
Register:
with in A CPU A high Speed Storage area is Called
Register which are directly linked to a control unit
Basic Purpose is to store operand in Arthematic Calculations
They are Like a Scratch pad Ram inside a Processor like Ram.
They Are Named as A,B,C,D .
USED:
When we need more than one data element inside the processor at one time.
……..
Slide 19 of 53Ver. 1.0
Programming in C
REGISTER CATEGORIES iApx88
REGISTERS/IApx88
General Purpose Index Registers Status Control Flag Register Segment
Slide 20 of 53Ver. 1.0
Programming in C
REGISTER CATEGORIES iApx88 / General Register
GENERAL REGISTER
AX BX CX DX
Slide 21 of 53Ver. 1.0
Programming in C
INDEX REGISTER
INDEX REGISTER
BP SP SI DI
Slide 22 of 53Ver. 1.0
Programming in C
Status Control Register
Status Control REGISTER
IP
Slide 23 of 53Ver. 1.0
Programming in C
FLAG REGISTER
Flag REGISTER
DF IF CF OF
Control FLagStatus Flag
TF SF ZF
Slide 24 of 53Ver. 1.0
Programming in C
SEGMENT REGISTER
SEGMENT REGISTER
CS DS SS ES
Slide 25 of 53Ver. 1.0
Programming in C
Accumulator Register: Central Register
All Mathematical And Logical operation are Performed on it.
Word size of processor is defined by Accumulator .
Index Register : Hold Address not Data .
Flag Register: it is Meaning Less As Whole .Individual Bit carry different Meaning it is of 8 bit ,16,32bit like Accumulator But as unit it is Meaning Less commonly Carry Flag is Used
16 bit num + 16 bit Accumulator=17 the 17 bit is placed as carry without this No Meaning
REGISTER: MAIN POINTS
Slide 26 of 53Ver. 1.0
Programming in C
REGISTER: MAIN POINTS
Program Counter or Instruction Pointer:
Every thing Must be Translated into Binary for our Processor to
understand & order of Instruction is controlled by this Register.
INSTRUCTION GROUP:
Data Movement Instruction
Mov ax,bx
Lad 123456
Slide 27 of 53Ver. 1.0
Programming in C
Instruction Group Continue
ALU INSTRUCTION:
Logical OR
Logical And
Logical XOR
and ax,1345
and bx ,0534
Add bx,[1200]
Data placed at1200
Slide 28 of 53Ver. 1.0
Programming in C
Instruction Group ContinueProgram Control Instruction
Instruction pointer points to next instruction and instruction run one after other with the help of this
register
I.E Flow Control
Cmp ax,0
Jne 12345
SPECIAL INSTRUCTION:
Change the behaviour of Processor
Cli
sti
Changing theFlow of
instructions
Clear the intrupt flag & SET IT
Slide 29 of 53Ver. 1.0
Programming in C
GENERAL REGISTER:
AX,BX ,CX and DX are General Purpose Register
“X” in there name Stand For Extended meaning 16 bit.
AX mean we are referring to 16 bit “A “ Register.
UPPER & LOWER BYTE:
are Separately Available as AH( A high Byte)
AL(A low BYTE)
All General Purpose Register can be Accessed as 16 bit register or as two 8 bit register
AX::: ACCUMULATOR
BX::: BASE (role in Memory Addressing)
CX::: Counter (work with automatic Count)
DX::DESTINATION ( act as destination in I/O)
Slide 30 of 53Ver. 1.0
Programming in C
INDEX REGISTER:
SI are Stand for Source INDEXDI stand for Destination INDEXINDEX REGISTER HOLD ADDRESSIntel Allow MATHEMATICAL & LOGICAL OPERATIONSSTRING INSTRUCTION: A SPECIAL CLASS of Instruction is Called String instructionSI and DI are 16bit and cannot be used as 8 bit register pairIP:(Instruction Pointer):contain the Adress of Next Instruction to be Executed NO Memory Access or Mathematic is Done SP(Stack pointer)::Memory pointer and is Used indirectly by set of instructionsBP(base pointer):: Memory pointer contain the adress in the Special Area of memory called STack
Slide 31 of 53Ver. 1.0
Programming in C
FLAG REGISTER is Not Meaning Full As a Whole But it was Bitwise significant .
CARRY FLAG: when two 16 bit num are added the answer is 17 bit long the extra bit which could not Fit in the target register is placed in the carry flag
PARITY FLAG::odd or even one bit only: this flag is used to verify the integrity of data.
Auxiliary Carry : during operation if a carry goes from one nibble to another is called Auxiliary FLAG
Zero FLAG: if the last logical instruction or mathematical instruction produced zero the zero flag is set:
Sign Flag:
-ve number is represented as 1 +ve num it is zero
Trap Flag:special role in debugging
Intrupt Flag: interruption of processor is disable or enable by making this bit zero or one
Direction Flag: specially related , this flag tells wheather the current operation has to be done
FLAG REGISTER:
Slide 32 of 53Ver. 1.0
Programming in C
SEGMENT REGISTER:
The
CS (code segment register)
DS(Data Segment Register)
SS(Stack Segment)
ES(Extra Segment Register)
…………………
Slide 33 of 53Ver. 1.0
Programming in C
SAMPLE PROGRAM
Org[0x0100]mov ax,5add ax,bxmov bx,15add ax,bx
mov ax,0x4c00Int 0x21