cse 331/ete 332/eee 332 microprocessor and assembly language programming presented by dr. shazzad...

27
CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Upload: damon-bellow

Post on 14-Dec-2015

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

CSE 331/ETE 332/EEE 332Microprocessor and Assembly

Language Programming

Presented ByDr. Shazzad Hosain

Asst. Prof. EECS, NSU

Page 2: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Books

• Fundamentals of Digital Logic and Microcomputer Design – M. Rafiaquzzaman

• The Intel Microprocessors 8086/8088 … , and Pentium Pro Processors – Barry B. Brey

• Assembly Language Programming and Organization of the IBM PC – Ytha Yu, Charles Marut

Page 3: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Mark DistributionItems Percentage

Attendance 5%

Quizzes 25%

Mid Term 25%

Lab 10%

Final 35%

Total 100%

http://www.northsouth.edu/php/faculty/shazzad/teaching.html and follow the corresponding link.

There will be no makeup for quizzes or exams. For details please visit

Best 3 out of 5

Page 4: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Assembly Language Programming

Page 5: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

What is Microcomputer?

Page 6: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The Microprocessor and Its Architecture

• ALU (Arithmetic and Logic Unit)• The Control Unit• Registers

HDD

RAM

Cache Memory

Microprocessor

R1 R1

R3

Page 7: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The Programming Model

• Program visible registers– We can access via programs

• Program invisible registers– We can not access via programs

Page 8: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Registers

16 bit Segment registers

Page 9: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Example Data

• If AX = 20A2H then AH = 20H, AL = A2H• In other words, if AH = 1CH and AL = A2H then AX = 1CA2H

0010 0000 1010 0010

AH AL

AX

Page 10: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGS register• FLAGS indicate the condition of the MP• Also control the operations• FLAGS are upward compatible from 8086/8088

to Pentium/Pentium Pro

Figure 2.2: The EFLAG and FLAG registers

Page 11: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGs

• Carry Flag – C – C = 1 if there is a carry out from the msb on addition– Or, there is a borrow into the msb on subtraction– Otherwise C = 0– C flag is also affected by shift and rotate instructions

1010101011101010

111010100 C = 1, in this case

Page 12: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGs

• Parity Flag – P – P = 1 for even parity, if number contains even

number of ones– P = 0 for odd parity, if odd number of ones

10101010 10101011

P = 1 P = 0Even number of ones Odd number of ones

Definition changes from microprocessor to microprocessor

Page 13: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGs

• Zero Flag – Z– Z = 1 for zero result– Z = 0 for non-zero result

• Sign Flag – S– S = 1 if msb of a result is 1, means negative number– S = 0 if msb of a result is 0, means positive number

Page 14: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGs

• Trap Flag – T– Enables trapping through an on-chip debugging feature– T = 1 MP interrupts the flow of a program, i.e. debug mode is

enabled– T = 0 debug mode is disabled

• Direction Flag – D– Selects increment/decrement mode of SI and/or DI registers

during string instructions– D = 1, decrement mode, STD (set direction) instruction used– D = 0, increment mode, CLD (clear direction) instruction used

Page 15: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

The FLAGs

• Overflow Flag – O– O = 1 if signed overflow occurred– O = 0 otherwise– Overflow is associated with the fact of range of

numbers represented in a computer• 8 bit unsigned number range (0 to 255)• 8 bit signed number range (-128 to 127)• 16 bit unsigned number range (0 to 65535)• 16 bit signed number range (-32768 to 32767)

Page 16: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Signed vs. Unsigned Overflow

• Let, AX = FFFFh, BX = 0001h and execute • ADD AX, BX

1111 1111 1111 1111+ 0000 0000 0000 00011 0000 0000 0000 0000

AXBX

• Unsigned interpretation– Correct answer is 10000h = 65536– But this is out of range.– 1 is carried out of msb, AX = 0000h, which is wrong– Unsigned overflow occured

• Signed interpretation– FFFFh = -1, 0001h = 1, summation is -1+1 = 0– Singned overflow did not occur

Page 17: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

How instructions affect the flags?

• Every time the processor executes a instruction, the flags are altered to reflect the result

• Let us take the following flags and instructions

• Sign Flag – S• Parity Flag – P• Zero Flag – Z• Carry Flag – C

• MOV/XCHG• ADD/SUB• INC/DEC• NEG

NoneAllAll except CAll (C = 1 unless result is 0)

Page 18: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Example 1

• Let AX = FFFFh, BX = FFFFh and execute ADD AX, BX FFFFh+ FFFFh1 FFFEh

The result stored in AX is FFFEh = 1111 1111 1111 1110

SPZC

= 1 because the msb is 1= 0 because the are 15 of 1 bits, odd parity= 0 because the result is non-zero= 1 because there is a carry out of the msb on addition

Page 19: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Example 2

• Let AX = 8000h, BX = 0001h and execute SUB AX, BX 8000h- 0001h 7FFFh

The result stored in AX is 7FFFh = 0111 1111 1111 1111

SPZC

= 0 because the msb is 0= 0 because the are 15 of 1 bits, odd parity= 0 because the result is non-zero= 0 because there is no carry

Page 20: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Registers

16 bit Segment registers

Page 21: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Segment Registers

16 bit Segment registers

***

Segment 1

Segment 2

Segment n

0000hCS

8000hDS

A000hSS

Page 22: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

An Assembly Program#include <stdio.h>void main (){ int I, j ; ********* // comment *********}

Example 3-5 of Barry B. Brey’s book

Page 23: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

An Assembly Program Cont.

• What is the content of BX?

00h 10hAX

AH AL

10h 00h 00h 00h AAh AAhDATA1 DATA2 DATA3 DATA4

AAh AAhBX

BH BL

Page 24: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Assembly Language Structure

Page 25: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

An Assembly Program

• SMALL model allows one data segment and one code segment

• TINY model directs the assembler to assemble the program into a single segment

• DB for Define Byte (one single byte)• DW for Define Word (two consecutive bytes)

10h 00h 00h 00h AAh AAhDATA1 DATA2 DATA3 DATA4

Page 26: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

Another Example

Page 27: CSE 331/ETE 332/EEE 332 Microprocessor and Assembly Language Programming Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU

References

• Ch 6, Digital Logic and Microcomputer Design – by M. Rafiquzzaman

• Ch 2, Intel Microprocessors – by Brey• Ch 5, Assembly Language Programming – by

Charls Marut