SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Dr A Sahu
Dept of Computer Science &
Engineering
IIT Guwahati
• 8086
– Block diagram (Data Path), Registers
• Memory Model
– Stack, Data and Code Segment
• Instruction Set of x86
• Addressing mode
• Procedure and subroutine
• Examples programs in C/C++ assembly
• Peripheral device and Assembly program
AH AL
BH BL
CH CL
DH DL
SI (Source Idx )
DI (Dest. Idx)
BP (Base Ptr )
SP (Stack Ptr)
Z (Flag Reg)
CS (Code Seg Reg)
DS (Data Seg Reg )
ES (Extra Seg Reg )
SS (Stack Seg Reg)
IP (Intr Ptr)
Operand
InDirect
Temp A
Temp B
Temp C
Q6
Q5
Q4
Q3
Q2
Q1
Sequencer
Bus Interface
Unit
Execution
Unit
SUM
C BUS
A BUS
ALU
• AX - accumulator reg
• BX - base address reg
• CX - count reg
• DX - data reg
• SI - source index reg
• DI - dest index reg
• BP - base pointer.
• SP - stack pointer.
AH AL
BH BL
CH CL
DH DL
SI (Source Idx )
DI (Dest. Idx)
BP (Base Ptr )
SP (Stack Ptr)
CS (Code Seg Reg)
DS (Data Seg Reg )
ES (Extra Seg Reg )
SS (Stack Seg Reg)
IP (Intr Ptr)
Z (Flag Reg)
31 15 7 0
EAX
EBX
ECX
EDX
ESI
EDI
EBP
ESP
ECS
EDS
EES
ESS
EIP
EZ
• Stack
– automatic (default), local
– Initialized/uninitialized
• Data
– Global, static, extern
– BSS: Block Started by Symbol
– BBS: Uninitialized Data Seg.
• Code
– program instructions
• Heap
– malloc, calloc
Data
Code
Heap
Stack
BSS
int A;
int B=10;
main(){
int Alocal;
int *p;
p=(int*)malloc(10);
}
Data
Code
Heap
Stack
BSS
.model small
.stack 100h ; reserve 256 bytes of stack space
.data
message db "Hello world, I'm learning Assembly$”
.code
main proc
mov ax, seg message ; ax<-data seg. start addr.
mov ds, ax ; Initialize Seg Reg
mov ah, 09 ; 9 in the AH reg indicates Procedure
;hould write a bit-string to the screen.
lea dx, message ;Load Eff Address
int 21h
mov ax,4c00h ; Halt for DOS routine (Exit Program)
int 21h
main endp
end main
Memory Model: Segment Definition
• .model small
– Most widely used memory model.
– The code must fit in 64k.
– The data must fit in 64k.
• .model medium
– The code can exceed 64k.
– The data must fit in 64k.
• .model compact
– The code must fit in 64k.
– The data can exceed 64k.
• .medium and .compact are opposites.
hellodat SEGMENT BYTE 'DATA' ;Define the data segment
dos_pr EQU 9 ;define a constant via EQU
strng DB 'Hello World',13,10,'$‘; Define char string
hellodat ENDS
hellodat SEGMENT ;define a segment
dos_print EQU 9 ;define a constant
strng DB 'Hello World',13,10,'$' ;Define char string
hellodat ENDS
.data
dos_print EQU 9 ;define a constant
strng DB 'Hello World',13,10,'$' ;Define char string
Data Allocation Directives
• db : define byte dw: def. word (2 bytes)
• dd: def double word (4) dq : def quad word (8)
• equ : equate assign numeric expr to a name
.data
db A 100 dup (?) ; define 100 bytes, with no initial
values for bytes
db “Hello” ; define 5 bytes, ASCII equivalent of “Hello”.
dd PtrArray 4 dup (?) ;array[0..3] of dword
maxint equ 32767 ; define maxint=32767
count equ 10 * 20 ; calculate a value (200)
• Assemby code: Loop
– Loop simply decreases CX and checks if CX != 0, if
so, a Jump to the specified memory location
– LOOPNZ : LOOPs when the zero flag is not set
MOV CX,100
_LABEL: INC AX
LOOP _LABEL
MOV CX,10
_CMPLOOP:DEC AX
CMP AX,3
LOOPNE CMPLOOP
• Assemby code: Nested Loop: One CX register
mov cx, 8
Loop1: push cx
mov cx, 4
Loop2: stmts
loop Loop2
pop cx
stmts
loop Loop1
• Arithmetic
– ADD, SUB, MUL, DIV
– ADD AX, 5 AX = 0003  AX = 0008
• Logic
– AND, OR, XOR, NOT
– AND CH, DL CH = 11111111 DL = 00000010  CH=
00000010
• Bit manipulation
– SHL/SHR
– SHL AL, 1 AL= 101101010  01101010 ;(SHL by 1)
• Comparisons and jumps
– JMP, CMP, Jxx, CALL, RET
W = X + Y * Z
mov ax, y ;Must compute Y * Z first since
imul z ; multiplication has a higher
add ax, x ; precedence than addition.
mov w, ax
• Register : MOV AX, BX ; AX  BX
• Immediate : MOV AX, 3CH ; AX 3CH
• Direct : MOV [2000], AX ; 0(DSx10h+2000) AX
• Reg indirect:MOV [BX], AX ; 0(DSx10h+BX)AX
• Base+Indx:
MOV [BX+SI], AX ;0(DSx10h+BX+SI)AX
• RegRelative:
MOV [BX+4], AX ;0(DSx10h+BX+4)AX
• Base Relative + Index
MOV ARRAY[BX+SI], AX ;0(DSx10h+ARRAY+BX+SI)AX
• Scaled index
MOV [BX+2 x SI], AX ; 0(DSx10h+BX x 2+SI) AX
• Memory address written as
– SEGMENT:OFFSET
– Dereference offset with square brackets CS:[C494]
• DS is implicit: [1337] is same as DS:[1337]
• Input a single char from KBD and echo
– Registers used: AH = 1, AL = the character inputted from
keyboard.
– Ex: MOV AH,1
INT 21H
• Outputs a string of data, terminated by a $
– Registers used: AH = 9, DX = the offset address of the data to
be displayed.
– Ex: MOV AH,09
MOV DX,OFFSET MESS1
INT 21H
• Terminates a process
– Registers used: AH = 4CH, AL = binary return code.
– Ex: MOV AH,4CH
INT 21H
• Option 0H – Sets video mode.
– Registers used:
AH = 0H, AL = Video Mode. 7H/3H – Col/BW 80X25
– Ex: MOV AH, 0
MOV AL,7
INT 10H
• Option 2H – Sets the cursor to a specific location.
– Registers used:
AH = 2H, BH = 0H, DH = Row pos, DL = Col pos
– Ex: MOV AH,2
MOV BH,0
MOV DH,12
MOV DL,39
INT 10H
• putchar( ‘a‘ ) ;
• c = getchar() ;
mov dl, ‘a‘ ;dl = ‘a‘
mov ah, 2h ;character output subprogram
int 21h ; call ms-dos output character
mov ah, 1h ; keyboard input subprogram
int 21h ; char input, char is stored in al
mov c, al ; copy character from al to c
.model small
.stack 100h ; reserve 256 bytes of stack space
.data
.code
main proc
call print40Dot
mov ax,4c00h ; Halt for DOS routine (Exit Program)
int 21h
main endp
end main
PrintSpaces proc near ; print 40H dots
mov al, ' . '
mov cx, 40
mov ah, 2h
PSLoop: int 21H
loop PSLoop
ret
PrintSpaces endp
• MACRONAME MACRO {ARG}
• Examples
MOV_ASCII MACRO NUM, SRC,
DST
MOV CX, NUM
LEA SI, SRC
LEA DI, DST
REP MOVSB
ENDM
• Call macro and expand
– MOV_ASCII 5, 3320H, 4560H;
– MOV_ASCII 50H, 1000H, 2000H;
MOV CX, 05
LEA SI,3320H
LEA DI, 4560H
REP MOVSB
MOV CX, 50H
LEA SI,1000H
LEA DI, 2000H
REP MOVSB
• MACRONAME MACRO {ARG}
• Examples
ADDITION MACRO X, Y, Z
PUSH AX
MOV AX,X
ADD AX,Y
MOV Z,AX
POP AX
ENDM
• Call macro and expand
– ADDITION A1, A2, A3
PUSH AX
MOV AX,A1
ADD AX,A2
MOV A3,AX
POP AX
.model small
.data
N EQU X
.code
main proc
mov bx, N
call SUM_OF_N
mov ax,4c00H
int 21h
main endp
end main
SUM_OF_N proc near
cmp bx, 00
jz BX_O
push bx
dec bx
call SUM_OF_N
pop bx
BX_O: add ax, bx
ret
endp
OutsideProc proc near
jmp EndofOutside
InsideProc proc near
mov ax, 0
ret
InsideProc endp
EndofOutside: call InsideProc
mov bx, 0
ret
OutsideProc endp
char string[]=“My ASM string display”;
void main(){
Display (mystring) ;
}
void Display(char *string_addr[]) {
_asm{
mov bx, string_addr
mov ah,2 ; set DOS function 2
top : mov dl, [bx] ; display string
inc bx
cmp dl, 0
je bottom
int 21h
jmp top
bottom: mov dl,13 ;display clrf
int 21h
mov dl,10
int 21h
}
}
void DisplayN(int N) {
_asm {
mov ax, N
mov bx,10
push bx
L1: mov dx,0
div bx
push dx
cmp ax,0
jnz L1
L2: pop dx
cmp dl,10
je L3
mov ah,2
add dl,30h
int 21h
jmp L2
L3: mov dl, ‘ ‘
int 21h
}
}
Reference
• Putc & Getc: Assembly Program:
– http://www.csi.ucd.ie/staff/jcarthy/home/FirstScience.html
• W Tribel, A Singh, “The 8086/8088 Microprocessor”,
Pearson education india, 2nd, 2008
– Macros & Routine
• Brey B B, “The Intel Microprocessor”, Prentice Hall
India, 2005
– ASM inside C program
– Addressing mode
• Write and execute 8086 assembly language
program to find value of SUM of square of first
N number (for N=10, S=12+22+32+42+..102)
• Deadline: 21th Aug 2010, 11.55Mid night
• After deadline grading: Max 5 out of 10
• Send TXT version of program with file name
RollNo.txt to asahu@iitg.ernet.in with
Assignment one as subject of email
• Don’t submit copied one: will get Negative
marks
• Basic characteristics of peripheral devices
• Pin configurations of IO port
• Block device, Char device, Stream device
• Interrupts & ISR
• Mapping memory address to IO
• ………………
Lec06

Más contenido relacionado

La actualidad más candente

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
bpftrace - Tracing Summit 2018
bpftrace - Tracing Summit 2018bpftrace - Tracing Summit 2018
bpftrace - Tracing Summit 2018AlastairRobertson9
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflowsjohseg
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...GECon_Org Team
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이GangSeok Lee
 
Python opcodes
Python opcodesPython opcodes
Python opcodesalexgolec
 
A compact zero knowledge proof to restrict message space in homomorphic encry...
A compact zero knowledge proof to restrict message space in homomorphic encry...A compact zero knowledge proof to restrict message space in homomorphic encry...
A compact zero knowledge proof to restrict message space in homomorphic encry...MITSUNARI Shigeo
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterakaptur
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.lnikolaeva
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
 
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化MITSUNARI Shigeo
 
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...MITSUNARI Shigeo
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 

La actualidad más candente (20)

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
 
bpftrace - Tracing Summit 2018
bpftrace - Tracing Summit 2018bpftrace - Tracing Summit 2018
bpftrace - Tracing Summit 2018
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflows
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
The PDP-10 - and me
The PDP-10 - and meThe PDP-10 - and me
The PDP-10 - and me
 
Python opcodes
Python opcodesPython opcodes
Python opcodes
 
A compact zero knowledge proof to restrict message space in homomorphic encry...
A compact zero knowledge proof to restrict message space in homomorphic encry...A compact zero knowledge proof to restrict message space in homomorphic encry...
A compact zero knowledge proof to restrict message space in homomorphic encry...
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化
Lifted-ElGamal暗号を用いた任意関数演算の二者間秘密計算プロトコルのmaliciousモデルにおける効率化
 
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
R and cpp
R and cppR and cpp
R and cpp
 
N flavors of streaming
N flavors of streamingN flavors of streaming
N flavors of streaming
 

Similar a Lec06

Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)ilias ahmed
 
Instruction addressing and execution
Instruction addressing and executionInstruction addressing and execution
Instruction addressing and executionSilvia
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Siraj Ahmed
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarragaFabricio Galárraga
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2HarshitParkar6677
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptxHebaEng
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly LanguageAhmed M. Abed
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarizeHisham Mat Hussin
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineTechnogroovy
 

Similar a Lec06 (20)

Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)
 
Practical notes
Practical notesPractical notes
Practical notes
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction addressing and execution
Instruction addressing and executionInstruction addressing and execution
Instruction addressing and execution
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .
 
Taller Ensambladores
Taller EnsambladoresTaller Ensambladores
Taller Ensambladores
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarraga
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
 
Lecture6
Lecture6Lecture6
Lecture6
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
Lec05
Lec05Lec05
Lec05
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarize
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects Online
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 

Más de siddu kadiwal (14)

Chp10 sw constr
Chp10 sw constrChp10 sw constr
Chp10 sw constr
 
Lec14
Lec14Lec14
Lec14
 
Lec13
Lec13Lec13
Lec13
 
Lec11
Lec11Lec11
Lec11
 
Lec12
Lec12Lec12
Lec12
 
Lec10
Lec10Lec10
Lec10
 
Lec09
Lec09Lec09
Lec09
 
Lec08
Lec08Lec08
Lec08
 
Lec07
Lec07Lec07
Lec07
 
Lec04
Lec04Lec04
Lec04
 
Lec03
Lec03Lec03
Lec03
 
Lec02
Lec02Lec02
Lec02
 
Lec04
Lec04Lec04
Lec04
 
Ece iv-fundamentals of hdl [10 ec45]-notes
Ece iv-fundamentals of hdl [10 ec45]-notesEce iv-fundamentals of hdl [10 ec45]-notes
Ece iv-fundamentals of hdl [10 ec45]-notes
 

Último

Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxrajesshs31r
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesDIPIKA83
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Projectreemakb03
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchrohitcse52
 
Tachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsTachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsEpec Engineered Technologies
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfRedhwan Qasem Shaddad
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...soginsider
 
News web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceNews web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceAkashJha84
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Apollo Techno Industries Pvt Ltd
 
Technical Management of cement industry.pdf
Technical Management of cement industry.pdfTechnical Management of cement industry.pdf
Technical Management of cement industry.pdfMadan Karki
 
Guardians and Glitches: Navigating the Duality of Gen AI in AppSec
Guardians and Glitches: Navigating the Duality of Gen AI in AppSecGuardians and Glitches: Navigating the Duality of Gen AI in AppSec
Guardians and Glitches: Navigating the Duality of Gen AI in AppSecTrupti Shiralkar, CISSP
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide LaboratoryBahzad5
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Sean Meyn
 

Último (20)

Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display Devices
 
Lecture 4 .pdf
Lecture 4                              .pdfLecture 4                              .pdf
Lecture 4 .pdf
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Project
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
 
Tachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsTachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and Applications
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
 
News web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceNews web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experience
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
 
Présentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdfPrésentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdf
 
Technical Management of cement industry.pdf
Technical Management of cement industry.pdfTechnical Management of cement industry.pdf
Technical Management of cement industry.pdf
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
Guardians and Glitches: Navigating the Duality of Gen AI in AppSec
Guardians and Glitches: Navigating the Duality of Gen AI in AppSecGuardians and Glitches: Navigating the Duality of Gen AI in AppSec
Guardians and Glitches: Navigating the Duality of Gen AI in AppSec
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
計劃趕得上變化
計劃趕得上變化計劃趕得上變化
計劃趕得上變化
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
 

Lec06

  • 1. Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati
  • 2. • 8086 – Block diagram (Data Path), Registers • Memory Model – Stack, Data and Code Segment • Instruction Set of x86 • Addressing mode • Procedure and subroutine • Examples programs in C/C++ assembly • Peripheral device and Assembly program
  • 3. AH AL BH BL CH CL DH DL SI (Source Idx ) DI (Dest. Idx) BP (Base Ptr ) SP (Stack Ptr) Z (Flag Reg) CS (Code Seg Reg) DS (Data Seg Reg ) ES (Extra Seg Reg ) SS (Stack Seg Reg) IP (Intr Ptr) Operand InDirect Temp A Temp B Temp C Q6 Q5 Q4 Q3 Q2 Q1 Sequencer Bus Interface Unit Execution Unit SUM C BUS A BUS ALU
  • 4. • AX - accumulator reg • BX - base address reg • CX - count reg • DX - data reg • SI - source index reg • DI - dest index reg • BP - base pointer. • SP - stack pointer. AH AL BH BL CH CL DH DL SI (Source Idx ) DI (Dest. Idx) BP (Base Ptr ) SP (Stack Ptr) CS (Code Seg Reg) DS (Data Seg Reg ) ES (Extra Seg Reg ) SS (Stack Seg Reg) IP (Intr Ptr) Z (Flag Reg) 31 15 7 0 EAX EBX ECX EDX ESI EDI EBP ESP ECS EDS EES ESS EIP EZ
  • 5. • Stack – automatic (default), local – Initialized/uninitialized • Data – Global, static, extern – BSS: Block Started by Symbol – BBS: Uninitialized Data Seg. • Code – program instructions • Heap – malloc, calloc Data Code Heap Stack BSS
  • 6. int A; int B=10; main(){ int Alocal; int *p; p=(int*)malloc(10); } Data Code Heap Stack BSS
  • 7. .model small .stack 100h ; reserve 256 bytes of stack space .data message db "Hello world, I'm learning Assembly$” .code main proc mov ax, seg message ; ax<-data seg. start addr. mov ds, ax ; Initialize Seg Reg mov ah, 09 ; 9 in the AH reg indicates Procedure ;hould write a bit-string to the screen. lea dx, message ;Load Eff Address int 21h mov ax,4c00h ; Halt for DOS routine (Exit Program) int 21h main endp end main
  • 8. Memory Model: Segment Definition • .model small – Most widely used memory model. – The code must fit in 64k. – The data must fit in 64k. • .model medium – The code can exceed 64k. – The data must fit in 64k. • .model compact – The code must fit in 64k. – The data can exceed 64k. • .medium and .compact are opposites.
  • 9. hellodat SEGMENT BYTE 'DATA' ;Define the data segment dos_pr EQU 9 ;define a constant via EQU strng DB 'Hello World',13,10,'$‘; Define char string hellodat ENDS hellodat SEGMENT ;define a segment dos_print EQU 9 ;define a constant strng DB 'Hello World',13,10,'$' ;Define char string hellodat ENDS .data dos_print EQU 9 ;define a constant strng DB 'Hello World',13,10,'$' ;Define char string
  • 10. Data Allocation Directives • db : define byte dw: def. word (2 bytes) • dd: def double word (4) dq : def quad word (8) • equ : equate assign numeric expr to a name .data db A 100 dup (?) ; define 100 bytes, with no initial values for bytes db “Hello” ; define 5 bytes, ASCII equivalent of “Hello”. dd PtrArray 4 dup (?) ;array[0..3] of dword maxint equ 32767 ; define maxint=32767 count equ 10 * 20 ; calculate a value (200)
  • 11. • Assemby code: Loop – Loop simply decreases CX and checks if CX != 0, if so, a Jump to the specified memory location – LOOPNZ : LOOPs when the zero flag is not set MOV CX,100 _LABEL: INC AX LOOP _LABEL MOV CX,10 _CMPLOOP:DEC AX CMP AX,3 LOOPNE CMPLOOP
  • 12. • Assemby code: Nested Loop: One CX register mov cx, 8 Loop1: push cx mov cx, 4 Loop2: stmts loop Loop2 pop cx stmts loop Loop1
  • 13. • Arithmetic – ADD, SUB, MUL, DIV – ADD AX, 5 AX = 0003  AX = 0008 • Logic – AND, OR, XOR, NOT – AND CH, DL CH = 11111111 DL = 00000010  CH= 00000010 • Bit manipulation – SHL/SHR – SHL AL, 1 AL= 101101010  01101010 ;(SHL by 1) • Comparisons and jumps – JMP, CMP, Jxx, CALL, RET
  • 14. W = X + Y * Z mov ax, y ;Must compute Y * Z first since imul z ; multiplication has a higher add ax, x ; precedence than addition. mov w, ax
  • 15. • Register : MOV AX, BX ; AX  BX • Immediate : MOV AX, 3CH ; AX 3CH • Direct : MOV [2000], AX ; 0(DSx10h+2000) AX • Reg indirect:MOV [BX], AX ; 0(DSx10h+BX)AX • Base+Indx: MOV [BX+SI], AX ;0(DSx10h+BX+SI)AX • RegRelative: MOV [BX+4], AX ;0(DSx10h+BX+4)AX • Base Relative + Index MOV ARRAY[BX+SI], AX ;0(DSx10h+ARRAY+BX+SI)AX • Scaled index MOV [BX+2 x SI], AX ; 0(DSx10h+BX x 2+SI) AX
  • 16. • Memory address written as – SEGMENT:OFFSET – Dereference offset with square brackets CS:[C494] • DS is implicit: [1337] is same as DS:[1337]
  • 17. • Input a single char from KBD and echo – Registers used: AH = 1, AL = the character inputted from keyboard. – Ex: MOV AH,1 INT 21H • Outputs a string of data, terminated by a $ – Registers used: AH = 9, DX = the offset address of the data to be displayed. – Ex: MOV AH,09 MOV DX,OFFSET MESS1 INT 21H • Terminates a process – Registers used: AH = 4CH, AL = binary return code. – Ex: MOV AH,4CH INT 21H
  • 18. • Option 0H – Sets video mode. – Registers used: AH = 0H, AL = Video Mode. 7H/3H – Col/BW 80X25 – Ex: MOV AH, 0 MOV AL,7 INT 10H • Option 2H – Sets the cursor to a specific location. – Registers used: AH = 2H, BH = 0H, DH = Row pos, DL = Col pos – Ex: MOV AH,2 MOV BH,0 MOV DH,12 MOV DL,39 INT 10H
  • 19. • putchar( ‘a‘ ) ; • c = getchar() ; mov dl, ‘a‘ ;dl = ‘a‘ mov ah, 2h ;character output subprogram int 21h ; call ms-dos output character mov ah, 1h ; keyboard input subprogram int 21h ; char input, char is stored in al mov c, al ; copy character from al to c
  • 20. .model small .stack 100h ; reserve 256 bytes of stack space .data .code main proc call print40Dot mov ax,4c00h ; Halt for DOS routine (Exit Program) int 21h main endp end main PrintSpaces proc near ; print 40H dots mov al, ' . ' mov cx, 40 mov ah, 2h PSLoop: int 21H loop PSLoop ret PrintSpaces endp
  • 21. • MACRONAME MACRO {ARG} • Examples MOV_ASCII MACRO NUM, SRC, DST MOV CX, NUM LEA SI, SRC LEA DI, DST REP MOVSB ENDM • Call macro and expand – MOV_ASCII 5, 3320H, 4560H; – MOV_ASCII 50H, 1000H, 2000H; MOV CX, 05 LEA SI,3320H LEA DI, 4560H REP MOVSB MOV CX, 50H LEA SI,1000H LEA DI, 2000H REP MOVSB
  • 22. • MACRONAME MACRO {ARG} • Examples ADDITION MACRO X, Y, Z PUSH AX MOV AX,X ADD AX,Y MOV Z,AX POP AX ENDM • Call macro and expand – ADDITION A1, A2, A3 PUSH AX MOV AX,A1 ADD AX,A2 MOV A3,AX POP AX
  • 23. .model small .data N EQU X .code main proc mov bx, N call SUM_OF_N mov ax,4c00H int 21h main endp end main SUM_OF_N proc near cmp bx, 00 jz BX_O push bx dec bx call SUM_OF_N pop bx BX_O: add ax, bx ret endp
  • 24. OutsideProc proc near jmp EndofOutside InsideProc proc near mov ax, 0 ret InsideProc endp EndofOutside: call InsideProc mov bx, 0 ret OutsideProc endp
  • 25. char string[]=“My ASM string display”; void main(){ Display (mystring) ; } void Display(char *string_addr[]) { _asm{ mov bx, string_addr mov ah,2 ; set DOS function 2 top : mov dl, [bx] ; display string inc bx cmp dl, 0 je bottom int 21h jmp top bottom: mov dl,13 ;display clrf int 21h mov dl,10 int 21h } }
  • 26. void DisplayN(int N) { _asm { mov ax, N mov bx,10 push bx L1: mov dx,0 div bx push dx cmp ax,0 jnz L1 L2: pop dx cmp dl,10 je L3 mov ah,2 add dl,30h int 21h jmp L2 L3: mov dl, ‘ ‘ int 21h } }
  • 27. Reference • Putc & Getc: Assembly Program: – http://www.csi.ucd.ie/staff/jcarthy/home/FirstScience.html • W Tribel, A Singh, “The 8086/8088 Microprocessor”, Pearson education india, 2nd, 2008 – Macros & Routine • Brey B B, “The Intel Microprocessor”, Prentice Hall India, 2005 – ASM inside C program – Addressing mode
  • 28. • Write and execute 8086 assembly language program to find value of SUM of square of first N number (for N=10, S=12+22+32+42+..102) • Deadline: 21th Aug 2010, 11.55Mid night • After deadline grading: Max 5 out of 10 • Send TXT version of program with file name RollNo.txt to asahu@iitg.ernet.in with Assignment one as subject of email • Don’t submit copied one: will get Negative marks
  • 29. • Basic characteristics of peripheral devices • Pin configurations of IO port • Block device, Char device, Stream device • Interrupts & ISR • Mapping memory address to IO • ………………