Assembly Language Exam Solutions 2005-2009
Assembly Language Exam Solutions 2005-2009
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
[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
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
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
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
2. Perform the following operations on 4 bits, and specify the values of the indicators.
CF, ZF, SF, OF, and PF:
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
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
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]
MOV BX, AX
MOV AX, 03h
AND AX, [SI+6]
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
1. Give the position of the indicators CF, ZF, SF, PF, and OF at the end of execution of the
following instructions
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
Exercise I:
Exercise II:
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
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
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
• 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
Exercise I:
1. Specify the role of each of the following registers:
CS, DS, SP and IP
Exercise II:
• Read the data from the stack by comparing them. Sort the highest value.
big in the DX register
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
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 :
PART III :
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
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
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
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
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 :
; Main program
START:
move R6, #30h Put 30H in the reistreR6
nbr : orl AR6, #01010101B Store the result of the logical operation
Or in R6
END
Sidi Mohamed Ben Abdellah University
Faculty of Sciences and Techniques
Department of Industrial Engineering
1. Detail the steps for executing the following two instructions specifying
the addressing mode:
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
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
Exercise III:
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
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.
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
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.
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
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
CMP Comparison
NOT Logical inversion
AND ET logic
OR Inclusive or
XOR Exclusive OU
TEST ET logic without result (positions the indicators)
Offsets:
Rotations :
WIRING INSTRUCTIONS
Conditional connections:
Indicators
Unsigned arithmetic
Signed arithmetic
Unconditional connections:
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
MOV Transfer
PUSH Loading the stack
POP Discharge of the battery
XCHG Exchange
XLAT Octet Translation
Addresses:
Indicators:
{"Entrées":"Entries","sorties":"Exits"}