0% found this document useful (0 votes)
9 views48 pages

Assembly Language Exam Solutions 2005-2009

The document presents exercises and solutions from an industrial computer science exam, addressing concepts of programming in assembly language. The problems include data manipulation in memory, interfacing with peripherals, and operations on arrays. The provided solutions illustrate the assembly instructions and control structures necessary to solve the posed problems.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views48 pages

Assembly Language Exam Solutions 2005-2009

The document presents exercises and solutions from an industrial computer science exam, addressing concepts of programming in assembly language. The problems include data manipulation in memory, interfacing with peripherals, and operations on arrays. The provided solutions illustrate the assembly instructions and control structures necessary to solve the posed problems.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sidi Mohamed Ben Abdellah University

Faculty of Sciences and Techniques


Industrial Engineering Department

MST Industrial Engineering

Industrial Informatics Exam 2005 - 2006

Problem I
Write a program in assembly language that performs the following operations:
1. Loading the following data into memory
• ["50","10","137","71","188","255","17"]
• 84h, BAh, 90h, B7h, 6Ah, F0h, 00h
Comparison between two elements in the same column.
3. Assigning the largest number to the stack.
The comparison must start from [Link] :
32, 10, 137, 71, 188, 255, 17
84h, BAh, 90h, B7h, 6Ah, F0h, 00h

1eracolumn last column

[Link] to DOS

Problem II
The interfacing between an LCD display and the parallel port of a PC is done as shown in the
figure below:
Parallel Port

D0 D0
D1 D1
D2 D2
D3 D3
D4 D4 LCD display
D5 D5
D6 D6 Vcc
D7 D7
E R/W RS Vcc

strobe

Select
printer

With:
E≡ (Enable) descending front march allowing the entry of the data to be displayed.
RS≡ (Select Register) works at the lower level validating the display.
a. Create a flowchart that displays the series 00h – FFh. The display of each
hard data 1s. Justify the different steps as well as the initialization values of the
records.
b. Translate the flowchart into C language.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution
Problem I:

DOSAGE
.MODELSMALL
.STACK0100H
.DATA
T1DB32H, 0AH, 89H, 47H, 0BCH, 0FFH, 11H
T2DB84H, 0BAH, 90H, 0B7H, 6AH, 0F0H, 00H
.CODE
START:
MOVAX @DATA
MOVDS AX
MOVAH 00H
MOVBX OFFSETT1
MOVCX, 7
LOOP:MOVAL, [BX]
CMPAL, [BX+7]
JASORTIE
MOVAL, [BX+7]
OUTPUT:PUSHAX
INCBX
LOOP
MOVAX 4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

MST Industrial Engineering

Industrial computing exam 2005 - 2006

Write a program in assembly that performs the following operations:

Type two characters on the keyboard.

2. Calculate the sum of the ASCII codes of the two characters.

3. Display the corresponding character.

The 3 operations must be repeated 5 times before proceeding to return to DOS.


We will put operation 1 in a subprogram.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution
DOSSEG
.MODELSMALL
.CODE
START:
MOVCX, 05H
LOOP:CALLENTRY
MOVE DL, AL

CALLSAISIE
ADD,AL
MOVAH,02H
INT21H
LOOP
MOVAX,4C00H
INT21H
INPUTPROCNEAR
MOVE,01H
INT21H
RET
ENDINPUT
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculté desSciences etTechniques
Department of Industrial Engineering

MST Industrial Engineering

Industrial Computer Exam 2007 - 2008

ASCII code represents each character in 8 bits (1 byte). The most significant bit
is always equal to 0. The codes of the lowercase alphabetic letters follow each other and
variant from 61h to 7Ah. When the 6th bit changes to 0, the character takes the form
uppercase.
Example: The ASCII code of a is 61h : 0 110 0 0 01
When A is capitalized, the code becomes 41h: 0 100 0 0 0 1

Write an assembly program that must:

1. Put the ASCII codes of all lowercase letters (a … z) in the stack.

2. Convert lowercase characters to uppercase characters by displaying them


one by one.

3. Return to DOS.

We will put the transformation of a character and its display in the form of a sub
programme.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Solution:

DOSSEG
.MODELSMALL
.STACK0100H
.CODE
START:
MOVAL,61H
SAUT:PUSHAX
INCAX
CMPAL,7AH
JBESAUT
MOVSI,02H
LOOP: CALL TRANSFORMATION
ADDSI,02H
CMPDL,41H
Jaboule
MOVAX,4C00h
INT21H

PROXIMAL TRANSFORMATION
MOVBP,SP
MOVDL, [BP+SI]
ANDDL,0DFH
MOVAH,02H
INT21H
RET
TRANSFORMATIONENDP
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

MST Industrial Engineering

Industrial Computing Exam 2008 - 2009

1. Specify the addressing mode for each of the following instructions:

MOV AL, [000B]


ADD AL, C4h
MOV [BX], 00h
MOV AX, 0FFh

2. Perform the following operations on 4 bits, and specify the values of the indicators.
CF, ZF, SF, OF, and PF:

1010 + 0101 and 1112

3. What are the roles of the following registers:


IP and SP?

4. Write the following assembly program:

• Write in memory 18h, 11h, 29h, 04h, 20h


• Store the minimum value of the array in the stack (reading from the
memory)
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution:
EXERCISE 4:

DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB18H, 11H, 29H, 04H, 20H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVAH,00H
MOVBX, OFFSET T1
MOVCX,4
MOVAL, [BX]
LOOP:
CMPAL, [BX+1]
JBS1
MOVAL, [BX+1]
S1:INCBX
LOOP
PUSHAX
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculté desSciences etTechniques
Department of Industrial Engineering

MST in Industrial Engineering

2008 - 2009 Industrial Computing Retake Exam

1. Detail the principle of all addressing modes of the 80x86.

2. Create the following assembly program:

• Create the following table in memory: 01 00 02 00 03 00 04 00


• Sort the number of null values in this array (read the
data from the table
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Solution:
DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB01H, 00H, 02H, 00H, 03H, 00H, 04H, 00H
.CODE
START:
MOVAX, @DATA
MOVDS, AX
MOVE,00H
MOVBX, OFFSET T1
MOVAL,08H
MOVCX,AL
OUTPUT:CMP[BX],00H
JNZS1
JMPS2
S1:DECAL
S2:INCBX
LOOPSORTIE
PUSHAX
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

Master's in Industrial Engineering

Microprocessor exam 2008 - 2009

1. Among the following instructions, indicate those that are incorrect and correct them.
the

PUSH AL
ROL AX, 2
MOVE AX, var
MOVE AX, BL
MOV AX, [0001]

2. Detail the steps of executing the following two instructions specifying


the addressing mode :

MOV BX, AX
MOV AX, 03h
AND AX, [SI+6]

3. Citer tous les registres du 80x86 en indiquant leurs rôles.

4. Write the following assembly program


• Create the following table in memory: 01 00 02 00 03 00 04 00
• Count in AX the number of non-null values in this array (read the
data from the table)
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution 1:

EXERCISE 4:

DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB01H, 00H, 02H, 00H, 03H, 00H, 04H, 00H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVAH,00H
MOVBX, OFFSET T1
MOVAL,8
MOVCX,AL
OUTPUT:CMP[BX],00H
JES1
JMPS2
S1:DECAL
S2:INCBX
LOOPSORTIE
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution 2:

EXERCISE 4:

DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB01H, 00H, 02H, 00H, 03H, 00H, 04H, 00H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVAH,00H
MOVBX, OFFSET T1
MOVAL,8
MOVCX,AL
OUTPUT:CMP[BX],00H
JNES2
DECAL
S2:INCBX
LOOPSORTIE
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Master's in Industrial Engineering

2008-2009 Microprocessor Resit Exam

1. Give the position of the indicators CF, ZF, SF, PF, and OF at the end of execution of the
following instructions

MOVE AX, AAh


ADD AX, 11h
ADC AX, 45h
Specify the content of AX.

2. What is the procedure followed by the processor during a subroutine call?


program with parameter passing by stack.

3. Create the following assembly program:

• Create the following table in memory:

01h, 00h, 02h, 00h, 03h, 00h, 02h, 00h


01h, 02h, 02h, 01h, 03h, 00h, 04h, 00h

• Add up all the columns and stack the elements of the


columns that yield a value of 6.
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Industrial Engineering Department

Solution:
EXERCISE 3:

DOSAGE
.MODELSMALL
.STACK0100H
.DATA
T1DB01H, 00H, 02H, 00H, 03H, 00H, 02H, 00H
T2DB01H, 02H, 02H, 01H, 03H, 00H, 04H, 00H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVAH,00H
MOVBX, OFFSET T1
MOVCX,8
OUTPUT: MOVEAL, [BX]
ADDAL, [BX+8]
CMPAL,06H
JNES1
PUSH[BX]
PUSH[BX+8]
S1:INCBX
LOOPSORTIE
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Master's in Industrial Engineering

Control No. 2 Microprocessor & Microcontroller 2009 - 2010

Exercise I:

1. List the index registers and specify their role


2. Recall the role of the PSW register as well as that of each indicator.
3. Why is memory divided into several segments of 64 KB each?

Exercise II:

1. Write the following assembly program:

• Load the data segment with 3 different values


• Compare them and put the highest value in the stack
• Add the 3 values from memory and stack the result
• Stack the three values of the memory

[Link], using a diagram, the situation of the stack (Values, SP position)


Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

Solution:
Exercise II:

DOSSEGA JAS2
.MODELSMALL MOVAL, VAR3
.STACK0100 H S2:
.DATA PUSHAX
VAR1DB01H MOVAL, VAR1
VAR2DB04H ADDAL, VAR2
VAR3DB03H ADDAL, VAR3
.CODE PUSHAX
START: MOVBX, OFFSETVAR1
MOVAX, @DATA MOVCX, 3
MOVDS, AX S3:
MOVAH,00H MOVAL,[BX]
MOVAL, VAR1 PUSHAX
CMPAL, VAR2 INCBX
JAS1 LOOPS3
MOVAL, VAR2 MOVAX,4C00H
S1: INT21H
CMPAL, VAR3 ENDSTART

SP F6h
0003
SPF8h
0004
SPFAh
0001
SPFCh
0008
SPFEh
0003
SP100h
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Technologies
Industrial Engineering Department

Master's in Industrial Engineering

Microprocessor & Microcontroller Exam 2009 - 2010

Exercise I:
1. What is the difference between a hardware interrupt and a software interrupt?
software?
2. Give the steps for handling a hardware interrupt
3. Indicate the type of addressing mode of the following instructions by explaining it.
data entry method

ADC AX, 50h


INC BX
MOVE DX, [SI+5]

Exercise II:

Write a program in assembly that displays the letters of the alphabet in lowercase and
IN CAPITAL LETTERS AS SHOWN IN THE EXAMPLE BELOW:

aAbBcC…zZ

Put into the form of subprograms

• Displaying a character
• The transformation of character
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution:

Exercise II:

DOSSEG DOSSEG
.MODELSMALL .MODELSMALL
.CODE .CODE
START: START:
MOVE BYTE, 61H MOVAL, 61H
SAUT: SAUT:
MOVDL,BL MOVDL,AL
CALL DISPLAY DISPLAY CALL
CALLTRANSFORMATION CALLTRANSFORMATION
DISPLAY CALL DISPLAYCALL
INCBL INCAL
CMPBL,7AH CMPAL,7AH
JBESAUT JBESAUT
MOVAX, 4C00H MOVAX,4C00H
INT21H INT21H
DISPLAYPROCNEAR DISPLAYPROCNEAR
MOVAH,02H MOVE,02H
INT21H INT21H
RET RET
DISPLAYENDP DISPLAYENDP

TRANSFORMATIONPROCNEAR TRANSFORMATIONPROCNEAR
ANDDL,0DFH ANDDL,0DFH
RET RET
TRANSFORMATIONENDP TRANSFORMATIONENDP
ENDSTART ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Master's in Industrial Engineering

Continuous assessment Microprocessor & Microcontroller 2010-2011

Exercise I:
1. Specify the role of each of the following registers:
CS, DS, SP and IP

2. What is the purpose of the flag register (PSW)?

Exercise II:

[Link] a program in assembly that performs the following operations:

• Put the values below onto the stack in this order:

18h, 11h, 29h, 04h, 20h

• Read the data from the stack by comparing them. Sort the highest value.
big in the DX register

[Link], using a diagram, the state of the stack after execution of


the stacking instruction. Specify the different values of SP.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Solution:
Exercise II:

DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB18H, 11H, 29H, 04H, 20H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVE,00H
MOVBX, OFFSET T1
MOVCX,5
OUTPUT:MOVAL, [BX]
INCBX
PUSHAX
LOOPSORTIE
POPDX
S1:CMPSP,100H
JZFIN
POPAX
CMPDL,AL
JAS1
MOVDL,AL
JMPS1
FIN:
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

Master's degree in Industrial Engineering

Microprocessor & Microcontroller Exam 2010-2011

PART I:

1. Briefly recall all the 80x86 registers, specifying the role of each.
registers.
2. Give the addressing mode of the following instruction and indicate the steps of
the execution: AND AX, [BX+SI+7]
3. Why do memory segments have a size of 64 KB?
4. Provide the architecture of the memory space specifying the addresses and the mode.
addressing of the microcontroller 80C535.
5. What is the difference between a general register and a SFR?
6. Citer 3 exemples de registres généraux et 3 exemples de registres SFR.

PART II :

Write a program in assembly that performs the following operations:


Input of four characters on the keyboard
2. Comparison of the four entered characters
3. Displaying the character whose ASCII code is the largest

Operation 1 must be carried out by a subroutine.


Note: The ASCII code of the entered character is placed in AL by the CPU
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

PART III :

We consider an LED diode connected to output 7 of port 1 of


microcontroller 80C535. We want to make the LED blink continuously, following two
different periods. The choice of the period is made using an external command.
(switch) connected to input 7 of port 4.

Write a program to load into the microcontroller, that offers the two
the following possibilities according to the previously described mode of operation:
If the switch is in the high state, we choose period 1.
If the switch is in the low state, we choose period 2

• Period 1: the ignition (extinction) duration is around 65.5 ms.


• Period 2: the duration of the ignition (extinction) is around 32.80 ms

Justify the choice of values to put in the registers to achieve the desired period.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution:
PART II:

DOSSEG
.MODELSMALL
.CODE
START:
MOVDL 00H
MOVCX, 04H
LOOP:CALL ENTRY
CMPDL,AL
JASAUT
MOVDL, AL
SAUT:
LOOP
MOVAH,02H
INT21H
MOVAX,4C00H
INT21H
ENTERPROCNEAR
MOVAH,01H
INT21H
RET
SAISIEENDP
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

PART III :

Solution 1:

CPU 80515
INCLUDE stddef51
USING bank0
SEGMENT code
ORG 0000H
START:
MOV R7, #80H
LOOP: CPL P1.7
CALL WAITING Start
JB P4.7 START
MOVE R7, #40H
SJMP LOOP R7← 80H

WAITING:
SAUT2: MOVE R6, #00H
CPL P1.7
SAUT1: DJNZ R6, SAUT1
DJNZ R7, SAUT2
RET
WAITING

END

R7← 40H Base Skin


P4.7
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Solution 2:

CPU 80515
INCLUDE stddef51
USING bank0
SEGMENT code
ORG 0000H
START:
CPL P1.7
JB P4.7 SKIN
HOLD WAITING2
SJMP BAS
SKIN: HOLD Start
BAS : SJMP START

WAITING1 :
CPL P1.7
MOVE R7, #80H
SAUT2: MOVE R6, #00H
SAUT1: DJNZ R6, SAUT1
DJNZ R7, SAUT2 P4.7
RET
WAITING2 :
MOVE R7, #40H
WAIT1 WAITING2
SAUT4: MOVE R6, #00H
SAUT3: DJNZ R6, SAUT3
DJNZ R7, SAUT4
RET

END
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Master's in Industrial Engineering

Microprocessor & Microcontroller Retake Exam


2010-2011

EXERCISE I:
Write the assembly program that executes the following operations:
• Créer le tableau : 01h, 00h, 02h, 00h, 03h, 00h, 04h, 00h.
• Count the number of null values.
• Put this number into the AX register and then onto the stack.

EXERCISE II :
Here is the program of the microcontroller 80C535:

CPU 80515
INCLUDE stddef51
USING bank0
SEGMENT code
ORG 0000H
START :
move R6, #30h
move 35h, #2Fh
move P1, #FFh
move the value 50h to register R0

nbr : orl AR6, #01010101B


cpl P1
cjne R6, #04, nbr
sjmp start
END

1. Provide the meaning of each instruction.


2. Calculate the duration of the program knowing that the machine cycle is on the order of 1µs.
UniversitéSidiMohamedBenAbdellah
Faculty of Science and Technology
Department of Industrial Engineering

Solution :

EXERCISE I :
DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DB01H, 00H, 02H, 00H, 03H, 00H, 04H, 00H
.CODE
START:
MOVAX, @DATA
MOVDS,AX
MOVAH,00H
MOVBX, OFFSET T1
MOVAL,08H
MOVCX,AL
OUTPUT: CMP[BX],00H
JNZS1
JMPS2
S1:DECAX
S2:INCBX
LOOPSORTIE
PUSHAX
MOVAX, 4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

EXERCISE II :

CPU 80515 Specify the type of CPU (instruction related to usage)


; Processor specific command list

INCLUDE stddef51 Definition of SFR

USING bank0 The register bank used

SEGMENT code Address counter positioning in the memory area

ORG 0000H Start address of the program (1eraorder from


from 0000H)

; Main program

START:
move R6, #30h Put 30H in the reistreR6

move 35h, #2Fh Load the address 35 from memory by


The constant 2FH

move P1, #FFh Assign the value FFH to port 1

move @R0, #50h Set the constant 50H in


The memory location addressed by R0

nbr : orl AR6, #01010101B Store the result of the logical operation
Or in R6

cpl P1 Supplement port 1

compare R6, #04, nbr Compare R6 with the value 04 if it is not


if not equal jump to number

SJMP START Jump to the address of START

END
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Master's degree in Industrial Engineering

Continuous assessment Microprocessor & Microcontroller 2011-2012

1. Detail the steps for executing the following two instructions specifying
the addressing mode:

MOV AX, var


AND AX, [SI+6]

2. Citer tous les registres du 80x86 en indiquant brièvement le rôle de chacun.

3. Write the assembly program that performs the following operations:


• Create the following series of hexadecimal values in the area
memory:

1001h, 0000h, 2002h, 0000h, A003h, 0000h, 1F04h, 0000h.

• Count the number of non-null values in this series (read the


data from memory.
• Put this number in the stack.
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

Solution:

EXERCISE 3:

DOSSEG
.MODELSMALL
.STACK0100H
.DATA
T1DW1001H, 0000H, 2002H, 0000H, 0A003H, 0000H, 1F04H, 0000H
.CODE
START:
MOVAX, @DATA
MOVDS, AX
MOVAH,00H
MOVBX, OFFSET T1
MOVAL,8
MOVCX, AX
OUTPUT:CMP[BX],0000H
JNES1
DECAL
S1:ADDBX,2
LOOPSORTIE
MOVAX,4C00H
INT21H
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

Master's in Industrial Engineering

Microprocessor & Microcontroller Exam 2011-2012

Exercise I:
What is the difference between a hardware interrupt and a software interrupt?
software?
2. Provide the steps for handling a hardware interrupt
3. For an 80C535 microcontroller, specify the location in memory of the
bases (banks) of general registers by stating their number.
4. Give some examples of SFR registers.

Exercise II:

Write a program in 80x86 assembly that displays the letters of the alphabet.
lowercase and uppercase as shown in this example:

aAbBcC…zZ

The display of the character must be handled as a subroutine.

Exercise III:

We consider an LED diode connected to output 7 of port 1 of


80C535 microcontroller. We want to make the diode blink continuously according to the
next period:
• the ignition duration is about 33.55 s
• the duration of the extinction is about 32.80 ms
1. give the flowchart of commands of the main program
2. give the flowchart of commands for the subprograms executing
the ignition and the extinction (justify the choice of values to load in the
records
3. write the program in 80515 assembly.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

EXERCISE II:
Solution1 : Solution2 :

HOLD DOSSEG
.MODELSMALL .MODELSMALL
.CODE .CODE
START: START:
MOVE AL, 61H MOVAL,61H
SAUT: SAUT:
MOVDL,AL MOVDL,AL
CALL DISPLAY DISPLAY CALL
ADD Decimal 20H ANDDL,0DFH
DISPLAY CALL CALL DISPLAY
INCAL ADDAL,20H
CMPAL,7AH INCAL
JBESAUT CMPAL,7AH
MOVAX, 4C00H JBESAUT
INT21H MOVAX,4C00H
DISPLAYPROCNEAR INT21H
MOVE,02H DISPLAYPROCNEAR
INT21H MOVAH,02H
RET INT21H
DISPLAYENDP RET
ENDSTART DISPLAYENDP
ENDSTART
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Exercise III:

Main program
2.1. Attente1 : 33,55 s
Beginning

Start

P1.7← 0B

R7← 80H

WAITING1

R6← 00H

CPL P1.7
2.2. Wait2: 32.80
R5← 00H
Start
WAITING2

R5← R5 - 1 No
R7← 40H R5 = 0

Yes
R6← 00H
R6← R6 - 1 No
R6 = 0

No R6← R6 - 1 Yes
R6 = 0
R7← R7 - 1 No
Yes R7 = 0

No R7← R7 - 1
Yes
R7 = 0
Return to
Yes program

Return to
program
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

3.

CPU 80515

INCLUDE stddef51
USING bank0
SEGMENT code
ORG 0000H
START:
MOV P1.7, #0B
HOLD WAITING1
CPL P1.7
HOLD WAITING2
SJMP START

WAIT1 :
MOV R7, #80H
SAUT3: MOVE R6, #00H
SAUT2: MOVE R5, #00H
SAUT1: DJNZ R5, SAUT1
DJNZ R6, SAUT2
DJNZ R7, SAUT3
RET
WAITING2 :
MOVE R7, #40H
SAUT5: MOVE R6, #00H
SAUT4: DJNZ R6, SAUT4
DJNZ R7, SAUT5
RET

END
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Industrial Engineering Department

Microprocessor & Microcontroller Retake Exam


2011-2012

EXERCISE I :

EXERCISE II :
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Industrial Engineering Department

Additional Exercise:
We consider 8 LED diodes connected to the outputs of port P1.

We want to continuously cycle through the 8 LEDs for two periods.


different.

The choice of scroll direction is made using a switch that controls


the bit 6 of port 4

• If the switch is in the high state, we choose scrolling to the right.


• If the switch is in the low state, we choose scrolling to the left.

The choice of the lighting period is made using an external command.


(switch) connected to input 7 of port 4.

• If the switch is in the high state, we choose period 1


• If the switch is in the low state, we choose period 2.

Period 1: the duration of the ignition (extinction) is around 65.5 ms


Period 2: the duration of the ignition (extinction) is approximately 32.80 ms

Write a program to load into the microcontroller that performs the


functions previously described.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Solution
CPU 80515
INCLUDE stddef51
USING bank0
SEGMENT code
ORG 0000H
START:
MOVE A, #FEH
SAUT3: MOVE R7, #80H
SAUT4 : MOVE P1, A
HOLD CALL
JB P4.6 SAUT1
RL A
SJMP SAUT2
SAUT1 : RR A
SAUT2 : JB P4.7, SAUT3
MOVE R7, #40H
SJMP JUMP4 Start

WAITING:
S2: MOVE R6, #00H A← 11111110B
S1: DJNZ R6, S1
DJNZ R7, S2
RET R7← 80H

END
P1← A

WAITING

Left Right
P4.6

RL A RR A

R7← 40H Bass P4.7 Skin


Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Summary of the 80x86 registers


General registers: these are registers for multiple uses, they will be used for
store intermediate results
AX: a register primarily used for arithmetic operations and for
inputs/outputs.
BX is an index register, it is used when accessing a memory area under
in table form, it represents the index of this table
CX: Serves as a counter for iterations in loops and operations on the
chains
DX: is an auxiliary accumulator

Segment registers: are often used to specify, during a write or read,


the memory segment where the operation needs to be performed.
CS (Code Segment): it is the memory block that contains the program or the code.
in progress
DS (Data Segment): the memory area where the program's data is located
SS (Stack Segment): Area of the stack where the CPU stores data
related to operations using the stack; including procedure calls and
interruptions
ES (Extra Segment): an additional segment that can receive data.

Index register: generally indicates the physical address that one wishes
to reach.
DI (Destination Pointer): it points to the destination in a segment, often ES,
where the CPU performs a write.
SI (Source Index): it points to the source in a segment, often DS, where the CPU
perform a reading
SP (Stack Pointer): it contains the offset of the address in a stack area. It is a
stack pointer
BP (Base Pointer): it is a base pointer register generally used with the
register SS.
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

Work register:
IP (Instruction Pointer): This register is associated with the segment register CS for
indicate the next instruction to execute. This register can never be modified
directly through jump instructions, programs, and interrupts.

Flags register (PSW): also called condition register, consists of flags


(flags) that indicate certain special states. These indicator bits can be tested
to determine the continuation of the program.
CF: it will be set to 1 if there was a carry during the last arithmetic instruction.
PF: the indicator set to 1 if the result of an operation contains an even number of bits
1.
AF: it is the weight retention 24used during decimal arithmetic operations.
ZF: it will be set to 1 if the result of an arithmetic instruction is zero.
SF: it will be set to 1 if the result of an instruction gives a negative number.
IT: it will be set to 1 if the result of adding 2 positive numbers gives a
negative number is inverse.
DF: is an indicator used when manipulating character strings.
IF: allows or does not allow the consideration of maskable external interrupts.
TF: ensures the visualization of the content of the registers and step-by-step operation.
The bit is set to 1.

X X X X OF DF IF TF SF ZF X AF X PF X CF
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

INSTRUCTION SET OF THE 8086/8088

ARITHMETIC INSTRUCTIONS
ADD Addition
ADC Addition with carrying
INC Increment of 1
AAA ASCII adjustment for addition
DAA BCD adjustment for addition

SUB Subtraction
SBB Subtraction with borrowing
DEC Decrementing by 1
NEG Complement to 2
CMP Comparison
AAS ASCII adjustment for subtraction
THE BCD adjustment for subtraction

MUL Unsigned multiplication


IMUL Signed multiplication
AAM ASCII adjustment for multiplication

DIV Unsigned division


IDIV Signed division
AAD ASCII adjustment for division

CBW Conversion of a byte to a word


CWD Conversion of a word into a double word

BIT PROCESSING INSTRUCTIONS


Logical functions:

CMP Comparison
NOT Logical inversion
AND ET logic
OR Inclusive or
XOR Exclusive OU
TEST ET logic without result (positions the indicators)

Offsets:

SHL Logical shift left


SAL Arithmetic shift to the left
SHR Logical shift right
SAR Arithmetic shift to the right

Rotations :

ROL Left turn


ROR Right rotation
RCL Left rotation, via the carry bit
RCR Right rotation, via the carry bit
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

WIRING INSTRUCTIONS
Conditional connections:

Indicators

JE/JZ If equal / if zero


JNE/JNZ If not equal / if not zero
JC Sicarry (held)
JNC If paternity (retain)
JO Overflow
JNO If overflow
JS If sign (negative)
JNS If no sign (positive)
JP/JPE If parity / if even parity
JNP/JPO If no parity / if odd parity

Unsigned arithmetic

JA/ JNBE If greater / if not less than or equal


JAE/JNB If greater than or equal / if not less than
JB/JNAE If less / if not greater than or equal to
JBE/JNA If less than or equal / if not greater

Signed arithmetic

JG/JNLE If greater / if not smaller or equal


JGE/JNL If greater than or equal / if not less than
JL/JNGE If smaller / if not larger or equal
JLE/JNG If less than or equal to / if not greater than

Unconditional connections:

JMP Unconditional jump


CALL Subroutine call
RET Return to the main program

Loops:

LOOP Loop
LOOPE/LOOPZ Loop if equal / if zero
LOOPNE/LOOPNZ Loop if not equal / if not zero
JCXZ Connection if CX = 0

Interruptions :

INT Interruption
INTO Interruption overflow
IRET Return from interruption
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering

DATA MOVEMENT INSTRUCTIONS


General:

MOV Transfer
PUSH Loading the stack
POP Discharge of the battery
XCHG Exchange
XLAT Octet Translation

Addresses:

LEA Loading the actual address


LDS Loading pointer using DS
THE Loading pointer using ES

Indicators:

LAHF Transfer of indicators to AH


SAHF Storage of AH in the indicators
PUSHF Loading indicators into the stack
POPF Unloading indicators from the stack

{"Entrées":"Entries","sorties":"Exits"}

IN Word or byte entry


OUT Output of word or byte

INSTRUCTIONS FOR TREATING STRINGS


MOVSB/MOVSW Chain movement
REP Repetition
STOSB / STOSW Chain storage
LODSB/LODSW Loading string
CMPSB/CMPSW String comparison
REPE/REPZ Repeat while equal to zero
REPNE/REPNZ Repeat as long as different from zero
SCASB/SCASW Balayage of a chain
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Industrial Engineering Department

ASCII TABLE CODE


Decimal Hexa Binary Character Decimal Hexa Binary Character
000 00 0000000 NUL 032 20 0100000 SPACE
001 01 0000001 SOH 033 21 A !
002 02 0000010 STX 034 22 B "
003 03 0000011 ETX 035 23 0100011 #
004 04 0000100 EOT 036 24 H $
005 05 0000101 ENQ 037 25 0100101 %
006 06 0000110 ACK 038 26 L &
007 07 0000111 BEL 039 27 0110111 '
008 08 0001000 BS 040 28 0101000 (
009 09 0001001 HT 041 29 0101001 )
010 0A 0001010 LF 042 2A 0101010 *
011 0B 0001011 VT 043 2B 0101011 +
012 0C 0001100 FF 044 2C 0101100 ,
013 0D 0001101 CR 045 2D 0101101 -
014 0E 0001110 SO 046 2E 0101110 .
015 0F 0001111 YES 047 2F 0101111 /
016 10 0001000 DLE 048 30 0 0
017 11 0010001 DC1 049 31 1 1
018 12 0010010 DC2 050 32 50 2
019 13 0010011 DC3 051 33 0110011 3
020 14 0010100 DC4 052 34 0 4
021 15 0010101 NAK 053 35 0110101 5
022 16 0010110 SYN 054 36 110 6
023 17 0010111 ETB 055 37 0110111 7
024 18 0011000 CAN 056 38 X 8
025 19 0011001 EM 057 39 0111001 9
026 1A 0011010 SUB 058 3A 0111010 :
027 1B 0011011 ESC 059 3B 0111011 ;
028 1C 0011100 FS 060 3C 0111100 <
029 1D 0011101 GS 061 3D 0111101 =
030 1E 0011110 RS 062 3E 0111110 >
031 1F 0011111 US 063 3F 0111111 ?
Decimal Hexa Binary Character Decimal Hexa Binary Character
064 40 1,000,000 @ 096 60 1,100,000 `
065 41 1000001 A 097 61 1000001 a
066 42 1000010 B 098 62 B b
067 43 C C 099 63 C c
068 44 D D 100 64 D d
069 45 101 E 101 65 101 e
070 46 110 F 102 66 1100110 f
071 47 G G 103 67 g g
072 48 1001000 H 104 68 1101000 h
073 49 I I 105 69 I I
074 4A J J 106 6A 1101010 j
075 4B K K 107 6B 1101011 k
076 4C L L 108 6C 1101100 l
077 4D M M 109 6D 1101101 m
078 4E N N 110 6E 1101110 n
079 4F O O 111 6F 1111111 o
080 50 1010000 P 112 70 1110000 p
081 51 1010001 Q 113 71 1110001 q
082 52 R R 114 72 r r
083 53 S S 115 73 s s
084 54 1000000 T 116 74 t t
085 55 1010101 U 117 75 117 u
086 56 V V 118 76 v v
087 57 1010111 W 119 77 1110111 w
088 58 1011000 X 120 78 1111000 x
089 59 Y Y 121 79 121 y
090 5A A Z 122 7A 1111010 z
091 5B 1011011 [ 123 7B 1111011 {
092 5C L \ 124 7C 1100100 |
093 5D 1011101 ] 125 7D 1111101 }
094 5E 1100110 ^ 126 7E 1111110 ~
095 5F 1111111 _ 127 7F 1111111 DEL
Sidi Mohamed Ben Abdellah University
Faculty of Science and Technology
Department of Industrial Engineering

INSTRUCTION SET OF THE 8051


University Sidi Mohamed Ben Abdellah
Faculty of Sciences and Techniques
Department of Industrial Engineering
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering
Sidi Mohamed Ben Abdellah University
Faculté desSciences etTechniques
Department of Industrial Engineering

You might also like