microprocessor & assembly language by team blackhole

16
SYLHET INTERNATIONAL UNIVERSITY Shamimabad, Baghbari, Sylhet-3100 Assignment Title: Microprocessors and Interfacing & Assembly Language Course Title: Microprocessors and Assembly Language Course Code: 333 Credit: 3 & Course Title: Microprocessors and Assembly Language Lab Course Code: 334 Credit: 1.5 Created by : TeamBlackHole TeamBlackHole V I R

Upload: md-abdus-sobur-sikdar

Post on 05-Aug-2015

275 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Microprocessor & Assembly language by team blackhole

SYLHET INTERNATIONAL UNIVERSITY

Shamimabad, Baghbari, Sylhet-3100

Assignment Title: Microprocessors and Interfacing & Assembly

Language

Course Title: Microprocessors and Assembly Language Course Code: 333

Credit: 3 &

Course Title: Microprocessors and Assembly Language Lab

Course Code: 334

Credit: 1.5

Created by : TeamBlackHole

TeamBlackHole

V

I R

Page 2: Microprocessor & Assembly language by team blackhole

Part-I: Microprocessor and Interfacing

1. Describe the sequence of signals that occurs on the address bus, the

control bus, and the data bus when a simple microcomputer fetches an

instruction?

Ans:

i. A microcomputer fetches each program instruction in sequence,

decodes the instruction, and executes it.

ii. The CPU in a microcomputer fetches instructions or reads data from

memory by sending out an address on the address bus and a Memory

Read signal on the control bus. The memory outputs the addressed

instruction or data word to the CPU on the data bus.

iii. The CPU writes a data word to memory by sending out an address on

the address bus, sending out the data word on the data bus, and

sending a Memory write signal to memory on the control bus.

iv. To read data from a port, the CPU sends out the port address on the

address bus and sends an I/O Read signal to the port device on the

control bus. Data from the port comes into the CPU on the data bus.

v. To write data to a port, the CPU sends out the port address on the

address bus, sends out the data to be written to the port on the data

bus, and sends an I/O Write signal to the port device on the control

bus.

2. What determines whether a microprocessor is considered an 8-bit, a 16-

bit or a 32-bit device?

Ans:

The word size (8 bits, 16 bits, or 32 bits) of a microprocessor is the size of the

data path in the execution unit. Typically, this is the size of the accumulator.

Note: This is the execution unit size, not the bus interface unit size. An example

where this matters is the 8088, which is a 16 bit computer running on an 8 bit

bus.

The 8085 is 8 bits. The 8086/8088 is 16 bits. The 80386 is 32 bits. Modern Intel

processors are 64 bits.

Page 3: Microprocessor & Assembly language by team blackhole

3.

a. How many address line does an 8086 have?

Ans:

There are 20 address lines on the 8086, A19 - A0, of which the low order 16,

A15 - A0, With 20 address lines, and the 8086 can address 1,048,576 bytes.

b. How many memory address does this number of address line allow the

8086 to access directly?

Ans: The 8086/8088 has 20 address lines. It can access 220, or 1MB, or

1,048,576 bytes of memory.

c. At any given time an 8086 works with four segments in this address

space, how many bytes are contained in each segment?

Ans: 64 kilobyte are contained in each segment.

4. What is the main difference between 8086 and 8088?

DIFFERENCE BETWEEN 8086 AND 8088 MICROPROCESSOR

8086 Microprocessor 8088 Microprocessor

8086 has 16-bit data lines. 8088 has 8-bit data lines.

8086 is available in three clock

speed 5 MHz, 8 MHz and 10 MHz

Whereas 8088 is available in two

clock speed 5 MHz and 8 MHz

The memory space of 8086 is

organized as two 512KB banks.

The memory space of 8088 is

implemented as single 1M*8

Memory bank.

8086 has 6-byte instruction queue. 8088 has 4-byte instruction queue.

The 8086 has BHE (Bank high

enable)

The 8088 has SSO status signal.

The 8086 can read or write 8-bit or

16-bit data at a time.

The 8088 can read/write 8-bit data

at a time.

The I/O voltages level for 8086 is

measured at 2.5 mA.

The I/O voltages level for 8086 is

measured at 2 mA.

The 8086 draws maximum supply

current of 360mA.

The 8086 draws maximum supply

current of 340mA.

Page 4: Microprocessor & Assembly language by team blackhole

DIFFERENCE BETWEEN 8085 AND 8086 MICROPROCESSOR

The difference between 8085 and 8086 are given below.

8085 Microprocessor 8086 Microprocessor

It is 8-bit Microprocessor It is 16-bit Microprocessor

It has 16-bit address line. It has 20-bit address line.

It has 8-bit data bus. It has 16-bit data bus.

The clock speed of 8085

microprocessor is 3 MHz

The clock speed of 8086 can vary

between 5, 8 and 10 MHz for three

different microprocessor.

It has 5 flags. It has 9 flags.

It does not support pipe-lining. It supports pipe-lining.

It’s operate on clock cycle with 50%

duty cycle.

It’s operate on clock cycle with 33%

duty cycle.

It does not support memory

segmentation

It support memory segmentation

The 8085 microprocessor has 6500

transistor.

The 8086 microprocessor has 29000

transistors.

The 8085 microprocessor is

Accumulator based processor.

The 8086 microprocessor is general

purpose register based processor.

The 8085 has no minimum or

maximum mode.

The 8086 has minimum and

maximum mode.

In 8085 microprocessor only one

processor is being used.

In 8086 more than one processor is

being used (additional external

processor can be used).

In 8085 microprocessor only 64 KB

memory is used together.

In 8086 microprocessor 1 MB is

used.

5.

a. Describe the function of the 8086 queue?

Ans: The 8086/8088 instruction queue is a buffer that holds opcode bytes that

have been prefetched by the bus interface unit. This speeds up operations of the

processor by helping to reduce fetch latency, i.e. to improve the probability that

an opcode byte fetched by the processor is already available.

b. What are the functions of execution unit in 8086 Intel?

Ans: Basically the function of execution unit in 8086 is to perform all arithmetic

and logic operations. It tells the Bus Interface unit (BIU) where to fetch

instructions and data from. It has 4 components: Control circuitry, ALU, Flag

registers and general purpose registers.

Page 5: Microprocessor & Assembly language by team blackhole

1. Control circuits-it directs all the internal operations.

2. ALU-performs all logic operations.

3. General purpose registers-used to store data during execution.

4. Flag registers-it has a 16bit flag register containing 9 flags that are set for

certain conditions during any operation. Ex: carry flag (whenever there is a

carry).

It also has a decoder to decode the fetched instructions.

c. How does the queue speed up processing?

Ans: The instruction prefetch queue speeds up the processing of

microprocessors by attempting to have the next opcode bytes available to the

execution unit before it actually needs them. This works because, statistically,

there is time spent by the execution unit in executing a particular instruction;

time that the bus interface unit can use to go ahead and pre-fetch the next

opcode bytes. Sometimes, this results in a loss of time, because the execution

unit may branch to some other location. Modern processors attempt to sidestep

that by using branch prediction algorithms.

6. If the code segment for an 8086 program starts at address 70400h, what

number will be CS register?

Ans: 7040H

7. What physical address represented by

a. 4370:561EH

b. 7A32:0028H

TeamBlackHole

V

I R

Page 6: Microprocessor & Assembly language by team blackhole

Ans: a.

43700

561𝐸

48𝐷1𝐸

Ans: b.

7A320

0028

7𝐴348

8. Why does 8086 use only 6 byte queue?

Ans: Because the longest instruction in instruction set is 6 bytes long. Hence

with a 6 byte long queue it is possible to pre-fetch even longest instruction in

the instruction set.

9. Describe the dived-by-zero interrupt?

Divide-by-zero interrupt: If u attempt to divide an operand by zero, the 8086

will automatically interrupt the currently executing program

More specifically, 8086 will automatically do a type zero interrupt if

– The result of a DIV operation or an IDIV operation is too large to

fit in the destination register.

At the end of each instruction cycle, 8086 checks to see if any interrupts have

been requested. If an interrupt has been requested – the 8086 responds to the

interrupt by stepping through the following series of major actions:

• It decrements the stack pointer by 2 and pushes the flag register on the

stack.

• It disables the INTR interrupt input – by clearing the interrupt flag (IF) in

the flag register.

• It resets the trap flag (TF) in the flag register.

• It decrements the stack pointer by 2 and pushes the current code segment

register contents on the stack.

Page 7: Microprocessor & Assembly language by team blackhole

• It decrements the stack pointer again by 2 and pushes the current

instruction pointer contents on the stack.

• It does an indirect fat jump to the start of the procedure you wrote to

respond to the interrupt.

10. List out the major steps in developing an assembly language program.

• Program Development Steps

• Defining the Problem

• Representing program operations

• Finding the right instructions

• Writing a program

Defining the problems

• Find out the problem. For example: Sensing temperature, detecting

fire, detecting smock, decoder-encoder, intelligent machine

controller etc.

Representing program operations

• Formula or sequence of operations used to solve a programming problem

is called as the algorithm.

• There are two ways of representing algorithms:

• Flowchart

• Structured programming and pseudo code

Finding the right instructions

• Instructions in 8086 are mainly divided into following categories

• Data Transfer Instructions

• Arithmetic Instruction

• Bit manipulation Instruction

Page 8: Microprocessor & Assembly language by team blackhole

• String Instruction

• Program execution transfer Instruction

• Processor control Instruction

Writing a program

• We need to do the following steps to write the program effectively:

• INITIALIZATION INSTRUCTIONS: used to initialize various

parts of the program like segment registers, flags and

programmable port devices.

• STANDARD PROGRAM FORMAT: it’s a tabular format

containing ADDRESS, DATA OR CODE, LABELS, MNEM,

OPERAND(S) and COMMENTS as the columns.

• DOCUMENTATION: you should document the program. E.g.

each page of the document contains page number and name of the

program, heading block containing the abstract about the program,

comments should be added wherever necessary.

11. Question no 8 in the chapter 3 in Microprocessors and interfacing 3rd

edition’s book.

Ans.

MOV AX, BX ; This copies the contents of the BX (075A) register into the

;AX register.

MOV CL, 37H ; This does the same as the above except that the number is

;given in hexadecimal. Hexadecimal numbers MUST begin

;with a digit and end with a "h". This copies 37H into CL

;register.

INC BX ; add one to contents of BX register.

MOV CX, [246BH] ; Copies the contents of memory location [246BH] into

;CX register.

MOV CX, 246BH ; This copies 246BH into CL register.

ADD AL, DH ; This add AL and DH into AL register.

Page 9: Microprocessor & Assembly language by team blackhole

MUL BX ; DX:AX = BX *AX

; Here BX= 07 5A and AX=42 35

; So DX:AX = 1E6B9A2h (1111001101011100110100010b)

; CF=0, OF=0.

DEC BP ; Decrement the value of base pointer by 1

; BP=2467h

DIV BL ; Divide AX by value in BL. result in AL, remainder in AH

; AL=AX/BL, AH=Reminder

; Here AX= 42 35 and BL=5A

; So AL=BCh and AH=0h

SUB AX, DX ; Subtract DX value from the AX value

; Here AX= 4235 and DX= 3302

; AX = F33h

OR CL, BL ; Preforms a Boolean OR operation. The result is stored in the

; destination register.

; Here CL = 04h and BL = 5Ah

; Sets CL = 0000 0000 0000 0100b

; and BL = 0000 0000 0101 1010b

; Sets CL = 0000 0000 0101 1110b

NOT AH ; Performs a Boolean NOT operation on the specified register.

; Here AH = 42h

; Sets AH =0000 0000 0100 0010

; Sets AH = 1111 1111 1011 1101b

ROL BX, 1 ; Rotates the register left by 1 bit. The MSB wraps over to the

;LSB. If more than 1 bit needs to be rotated, set the number of

;bits to rotate in the CL register first.

; Here AX = 0100 0010 0011 0101b

; So AX = 1000 0100 0110 1010b

AND AL, CH ; Performs a Boolean AND operation. The result is stored in

;the destination register.

; Here AL = 35h and CH= 00

Page 10: Microprocessor & Assembly language by team blackhole

; Sets AL= 0000 0000 0011 0101b

; Sets CH= 0000 0000 0000 0000b

; So AL = 0000 0000 0000 0000b

MOV DS, AX ; The Data Segment points to the starting address.

; Here AX = 42 35h

; So DS = 42 35h

ROR BX, CL ; Rotates the register right by 1 bit. The LSB wraps over to the

; MSB. If more than 1 bit needs to be rotated, set the number

;of bits to rotate in the CL register first

; Here BX= 07 5Ah and CL= 04h

; This BX= 0000 0111 0101 1010b

; So BX = 1010 0000 0111 0101b

Page 11: Microprocessor & Assembly language by team blackhole

12. Question no 11 in the chapter 3 in Microprocessors and interfacing 3rd

edition’s book.

Ans.

a. Copy AL to BL (MOV BL, AL)

b. Load 43h into CL (MOV CL, 43h)

c. Increment the contents of CX by 1 (INC CX, 1)

d. Copy SP to BP ( MOV BP, SP)

e. Add 07h to DL (ADD DL, 07h)

f. Multiply AL times BL ( MUL BL)

g. Copy AX to a memory location at offset 245Ah in data segment

(MOV [245Ah], AX)

h. Decrement SP by 1 (DEC SP, 1)

i. Rotate the most significant bit of AL into the least significant bit

position. ( ROL AL,1)

j. Copy DL into a memory location offset is in BX (MOV [BX],

DL)

k. Mask the lower 4 bits of BL (AND BL , 11110000b)

l. Set the most significant bit of AX to a 1 but don’t affect other bits.

( OR AX, 1000 0000 0000 0000b)

m. Invert the lower 4 bits of BL but don’t affect others. (XOR BL,

0000 1111b)

Page 12: Microprocessor & Assembly language by team blackhole

Part-II: Assembly Language

13. Which of the following names are legal in PC assembly language?

Ans.

a. TWO_WORDS (Legal)

b. ?1 (Legal)

a. Two words (Illegal because embedded blank is not allowed)

c. .@? (Legal)

d. $145 (Legal)

e. LET’S_GO (Illegal because (’) is not allowed)

f. T = . (Illegal because the period (.)must be first character

and embedded blank is not allowed)

14. Which of the following are legal numbers? If they are legal, tell whether

they are binary, decimal, or hex numbers.

Ans.

a. 246 (Legal , decimal)

b. 246h (Legal ,hexadecimal)

c. 1001 (Legal , decimal)

d. 1,101 (Illegal ',' is not allowed between digits)

e. 2A3h (Legal ,hexadecimal)

f. FFFEh (Illegal ,hexadecimal number must begin with digit)

g. 0Ah (Legal ,hexadecimal)

h. Bh (Illegal ,hexadecimal number must begin with digit)

a. 1110b (Legal ,binary)

i.

15. If it is legal, give data definition pseudo-ops to define each of the

following.

Ans.

a. A word variable A initialized to 52 (A DW 52)

Page 13: Microprocessor & Assembly language by team blackhole

b. A word variable WORD1, uninitialized (WORD1 DW ?)

c. A byte variable B, initialized to 25h (B DB 25h)

d. A byte variable C1, uninitialized (C1 DB ?)

e. A word variable WORD2, initialized to 65536 (WORD2 DW

65536)

f. A word array ARRAY1, initialized to the first five positive integers (i.e.

1-5) (ARRAY1 DW 1,2,3,4,5)

g. A constant BELL equal to 07h ( BELL EQU 07h)

h. A constant MSG equal to ‘THIS IS A MESSAGE$’ (MSG EQU

‘THIS IS A MESSAGE$’)

16. Suppose that the following data are loaded starting at offset 0000h

A DB 7

B DW 1ABCh

C DB 'HELLO'

a. Give the offset address assigned to variables A, B and C.

b. Give the hex contents of the byte at offset 0002h in hex.

c. Give the hex contents of the byte at offset 0004h in hex

d. Give the offset address of the character 'O' in “HELLO.”

Ans.

Offset Content Notes

0000 07 Content of A

0001 BC Part content of B

0002 1A Part content of B

0003 48 ASCII value of 'H' in hex

0004 65 ASCII value of 'e' in hex

0005 6C ASCII value of 'l' in hex

0006 6C ASCII value of 'l' in hex

0007 6F ASCII value of 'o' in hex

17. Tell whether each of the following instructions is legal or illegal.W1 and

W2 are word variables, and B1 and B2 are byte variables.

Ans.

a. MOV DS, AX (Legal)

b. MOV DS, 1000h (Illegal, can't move constant to segment register )

c. MOV CS, ES (Illegal, can't move between two segment registers)

d. MOV W1, DS (Legal)

Page 14: Microprocessor & Assembly language by team blackhole

e. XCHG W1, W2 (Illegal , can't exchange directly between two memory

location)

f. SUB 5,B1 (Illegal ,The destination can't be constant)

g. ADD B1, B2 (Illegal , can't add directly between two memory

location)

h. MOV W1, B1 (Illegal , can't add directly between two memory

location)

18. Using only MOV, ADD, SUB, INC, DEC, and NEG, translate the

following high-level language assignment statements into assembly

language. A, B, and C are word variables.

Ans.

a. A=B-A

MOV AX, A

NEG AX

ADD AX, B

MOV A, AX

b. A=-(A+1)

ADD A, 1

NEG A

c. C=A+B

MOV AX, A

ADD AX, B

MOV C, AX

d. B=3*B+7

Page 15: Microprocessor & Assembly language by team blackhole

MOV AX, B

ADD AX, B

ADD AX, B

ADD AX, B

ADD AX, 7

MOV B, AX

e. A=B-A-1

MOV AX, B

SUB AX, A

DEC AX

MOV A, AX

19. Write instructions (not a complete program) to do the following.

a. Read a character, and display it at the next position on the same line

b. Read an uppercase letter (omit error checking), and display it at the

next position on the same line in lower case.

Ans. a:

MOV AH, 1 ; keyboard input initialization for interrupt 21H

INT 21H

MOV BL, AL

MOV AH, 2 ; printing output initialization for interrupt 21h

MOV DL, 20H ; (20h) for blank space

INT 21H

MOV DL, BL

INT 21H

Ans. b:

Page 16: Microprocessor & Assembly language by team blackhole

MOV AH, 1 ; keyboard input initialization for interrupt 21h

INT 21H

MOV BL, AL

ADD BL, 20H ; convert to lowercase latter

MOV AH, 2 ; printing output initialization for interrupt 21h

MOV DL, 20H ; (20h) for blank space

INT 21H

MOV DL, BL

INT 21H

TeamBlackHole

V

I R

TeamBlackHole

V

I R