Showing posts with label Instruction-MOV. Show all posts
Showing posts with label Instruction-MOV. Show all posts

Thursday, May 20, 2010

7 segment LED programming with 8086/8088

Question
Given below is a snippet of a program that will display number “3” on a 7-segment LED which is connected at output port 08h.


Program:
MOV AL , 30h
OUT 08h, AL

7-segment detail
 7-segment LED (a-f) is connected to the port pins (1-7) respectively.
 7-segment LED is lid at low state

Assume a second 7 segment LED are connected to outport port 05h. Modify the program to display number “80” (the second LED will display number “8”).

Then assume the output from the port 05h and 08h will be inserted into another microprocessor (also at port 05h and 08h respectively). Write the program needed at the second microprocessor to receive the data. The data should be saved into any other location after retrieval.




Answer
 
30h =  011 0000 <-- gfedcba
 
a = 0
b = 0
c = 0
d = 0
e = 1
f = 1
g = 0

First LED (number 8,port 08h)
to display number 8, all will be active (active at low)

a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0

000 0000 = 00h

Second LED (number 0,port 05h)
to display number 0, all will be active except g (active at low)

a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 1

100 0000 = 60h

therefore the complete program would be

MOV AL , 00h
OUT 08h, AL //activate first LED to display 8
MOV AL , 60h
OUT 05h, AL ////activate first LED to display 0

-------------------------------------------------

the program at the second microprocessor to receive the input

IN AL,08h // retrieve the data
MOV DL,AL // store the data at another location
IN AL, 05h
MOV DH,AL

Monday, May 17, 2010

Shifting & Rotating

Question
Complete the following program so that at the end, AL will equal to FC and CF=1. Use only SHL followed by SAR AL,3 and finally RCR instruction.


MOV AL,33h // AL = 33h , initial CF=0
SHL ________
SAR AL,3 // CF-AL = 1-1111 1001
RCR ________

Answer

MOV AL,33H CF,AL : 0 0011 0011

SHL AL, 2 ; CF,AL : 0 1100 1100
SAR AL, 3 ; CF,AL : 1 1111 1001
RCR AL, 2 ; CF,AL : 0 1100 1100

Basic arithmetic assembly programming

Question

Indicate any value/data/register that has been change by every program line below

MOV BX, 0202h
MUL BL
ADD BX, ((AX))
MOV DX,ES:[0001h]
MOV [BP],CX



Answer

MOV BX, #0202h // BX = 0202h

MUL BL // AX = 0001h x 02h = 00002h

ADD BX, ((AX)) // BX = 11ABh + (0004)=11ABh + 0001h=11ACh

MOV DX,ES:[0001h] // DX =8967h

MOV [BP],CX // 50005 = 1F, 50006=CB

Arithmetic & Logic assembly programming

Question

Identify the new value of AX, BX dan CX after the program below.

MOV AX, 1234H

MOV BX, ABCDH
MOV CH, 1D
MOV CL, 255D
OR AH, 10H
AND BX , 1111000011110000b
NOT CX

Answer
 
AH  = 12h = 00010010

          10h = 00010000

AH OR AL = 00010010
--> AX = 1234h

BX = ABCD --> A0C0

CX = NOT ( 0AFF) = 1111 0101 0000 0000b = F500h

Assembly programming rules & LEA

Question

Identify the mistake in the following code, then rewrite a correct code.

LEA AX, DATA2

MOV ES:[0111h] , 1234H
ADD ES:[0111h], (AX)

Answer


The major mistake is the third line where there is an attempt to transfer data from memory location pointed by AX to another memory location in Extra Segment memory location. Memory to memory transfer is not permitted in 8086/8088 microprocessor.

An alternative code:

LEA AX, DATA2

MOV ES:[0111h] , 1234H
MOV DX,(AX)
ADD ES:[0111h],DX

Thursday, May 13, 2010

Flag Value (CF,PF,AF,ZF & CF) Tutorial

Question
State the final flag's value (CF, PF, AF, ZF & SF) for the operation given below. Explain the reason.
MOV AH, 9CH
MOV AL, 64H
ADD AH, AL

Answer
9C16 =  1001 11002
6416 =  0110 01002

AH + AL--> AH
AH = 9C16+6416 = 1 0000 00002 (number 1 is not included because the register size is only 8 bit,therefore the AH final value is 0016)

CF = 1 (got carry from D7)
PF = 1 (the number of 1 is even)
AF = 1 (got carry from D3 to D4)
ZF = 1 (because the final value is zero
SF = 0 (because the value at D15 is zero)

Stack programming tutorial

Question
Based on the following instruction, state the final value of AX,BX dan CX. Then draw the stack produce at 'PUSH CX' instruction. [Assume SS:5000h ; SP:0305h ]

 MODEL SMALL
.STACK
.STARTUP

MOV AX, 1000H
MOV BX, 2000H
MOV CX, 3000H

PUSH AX
PUSH BX
PUSH CX

POP AX
POP CX
POP BX

.EXIT
END

Answer

Final value:
AX=3000h
BX=2000h
CX=1000h

Address Data
50301    3000h
50303    2000h
50305    1000h

Tuesday, May 11, 2010

Rotating & Shifting tutorial

Question
Calculate the changes in AX and CF for each of the instruction in the program below (Assume initial CF=0)

MOV AX, F0h
SHL AH,3
SAR AH,4
RCR AH,1
OR   AH,AL

Answer

MOV AX, F0h
--> AX = 0000 0000 | 1111 0000
--> CF = 0


SHL AH,3
--> AH = 0000 0000 , shift to left 3 times will equal to 0000 0000 (no changes)
--> AX = 0000 0000 | 1111 0000
--> CF = 0



SAR AH,4
--> AH = 0000 0000 , shift arithmetic to right 3 times will make AH equal to 0000 0000 (no changes)

--> AX = 0000 0000 | 1111 0000
--> CF = 0

RCR AH,1
--> AH = 0000 0000 , shift with carry to right 1 times will make AH equal to 0000 0000 (no changes) and CF equal to zero
--> AX = 0000 0000 | 1111 0000
--> CF = 0


OR AH,AL
--> AH = 0000 0000
--> AL =  1111 0000
--> OR AH,AL --> AH = AH OR AL = 1111 0000 (F0h) --> AX = F0F0h , CF = 0


ROL AL,3
--> AL=11110000, rotate to left 3 times will make AL equal to 1000 0111 (87h)
--> AX = F087h, CF=1

Popular Posts

Latest Post from my Other Blog