Electronic Assignment Cover Sheet
School of Computing, Engineering& Mathematics
Student Name (First Name, Surname)
Student Number
Unit Name and Number
300076 Microprocessor Systems
Tutorial Group Number
N/A
Tutorial Day and Time
N/A
Class Day and Time
N/A
Unit Convenor
Dr Shahzad Asif
Title of Assignment
Assignment 2
Due Date
Friday 22 January 2021
(Distributed: Thursday 24 December 2020)
Date Submitted
Campus Enrolment
Sydney City Campus
STUDENT DECLARATION – by submitting your assignment electronically, you are agreeing that:
I hold a copy of this assignment if the original is lost or damaged.
I hereby certify that no part of this assignment or product has been copied from any other student’s work or from any other source except where due acknowledgement is made in the assignment.
No part of the assignment/product has been written/produced for me by any other person except where collaboration has been authorised by the subject lecturer/tutor concerned
I am aware that this work may be reproduced and submitted to plagiarism detection software programs for the purpose of detecting possible plagiarism (which may retain a copy on its database for future plagiarism checking).
Submission:
Your submission should be a word-document ONLY. The document should include questions, solutions, program, and screenshots. Submit your document online, on or prior to the due date.
Instructions:
This assignment is an individual work (except Questions 21-23). For other questions, you can discuss them with other students, but the final document should be written solely by you, using your own descriptions and explanations.
If you type your work on a university computer, your work could be copied by other students. Any identical works will be given a 0 mark. It is your responsibility to protect your work against plagiarism. If you don’t understand some questions, do NOT copy solutions from other students, please ask help from the lecturer. You are liable for any consequences from plagiarism.
300076 Microprocessor Systems
Assignment 2
1. If AX=F100H and DX=2D23H, list the sum and the contents of flag register bits CF,ZF, SF and PF after ADD AX,DX executes. (2 marks)
2. Develop a sequence of instructions that add AL,BL,CL,DL and AH, and saves the sum in the DH register. (2 marks)
3. Based on the following screenshot, determine the result in the concerned memory locations after XOR [SI],AX is executed. (2 marks)
4. Choose an instruction that decrements the SI register by 1. (1 mark)
5. Choose an instruction that adds 1 to the BL register. (1 mark)
6. If DL=44H and BH=3FH, list the difference after BH is subtracted from DL and show the contents of the flag register bits CF,ZF,SF and PF. (2 marks)
7. Develop a sequence of instructions that will clear the three rightmost bits of DH without changing DH and save the result in BH. (2 marks)
8. Develop a sequence of instructions that will set the five leftmost bits of DI without changing DI and save the result in SI. (2 marks)
9. Develop a sequence of instructions that will set the four leftmost bits of BX, clear the three rightmost bits of BX, and invert bit 8 of BX and save the result in BX. (3 marks)
10. Select an AND instruction that will
• AND AX with BX and save the result in BX. (1 mark)
• AND the data addressed by BX with CX and the save the result in memory addressed by BX. (1 mark)
• ANDBL with memory location specified by the address label WHAT and save the result in memory location WHAT. (2 marks)
11. Select an OR instruction that will
• OR BL with AH and save the result in AH. (1 mark)
• OR DX with SI and save the result in SI. (1 mark)
• OR the data addressed by BX with CX and the save the result in memory addressed by BX. (1 mark)
• OR the data stored 30 bytes after the location addressed by BP with AX and the save the result in the same memory locations. (1 mark)
• OR AH with memory location specified by address label WHEN and save the result in the memory location WHEN. (2 marks)
12. Select the correct instructions to perform each of the following tasks:
• shift DI right two places with zeros moved into the leftmost bits. (1 mark)
• shift DH right three places while leaving the sign bit of DH unchanged. (1 mark)
13. Which register is decremented by the loop instruction? (1 mark)
14. The following shows two different instructions, either of which can set DX to 0. What is the length of the machine code of each instruction? (Use EMU8086 to find their machine codes.)
XOR DX,DX
MOV DX,0 (1 mark)
15. (Interrupt Processing) The following is a partial dump of the Interrupt Vector Table:
(6 marks)
0000:0000 68 10 A7 00 65 04 70 00-16 00 DA 05 65 04 70 00
0000:0010 65 04 70 00 D7 04 00 C0-00 00 00 C9 53 FF 00 F0 0000:0020 85 98 00 F028 00 DA 05-3A 00 DA 05 52 00 DA 05
0000:0030 6A 00 DA 05 82 00 DA 05-9A 00 DA 05 65 04 70 00
Given the above contents of the interrupt vector table in memory,
a) Determine the 20-bit address of the interrupt service routine for the 0AH interrupt (segment not present).
b) Determine the 20-bit address of the interrupt service routine for the 06H interrupt (device not available).
16. (Interrupt type number generation) (6 marks)
(a) Search the internet to find the datasheets of 74148 and 74374. DON’T submit their datasheets. Use the information from the datasheets to describe the function of the circuit in the following figure.
(b) If it is required that the following 8 interrupt numbers are to be generated:
60H,61H,62H,63H,64H,65H,66H,67H, describe how to make connections.
17. (Assembly Programming) Write a program to (1) store0AH,09H,…,06Hinto 5 consecutive bytes of memory beginning at the segment base address of the data segment using the DB directive and (2)use the string instruction REP MOVSB to copy the above 5consecutive data to another block of consecutive memory locations in the same segment (i.e., the data segment). The address of the first memory of the destination block should have an offset address0010H. Type the program in emu8086, emulate and run the program. Include screenshots for the list file and memory display to show the data in the source block and destination block. (No credit will be given if you don’t use the REP MOVSB instruction.) (5 marks)
18. (Assembly Programming) The following is an assembly program. (15 marks)
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV CX, 3
MOV SI, OFFSET ARRAY
ITER: MOV AX, [SI]
XCHG AH, AL
ROL AX, 1
INC SI
AND [SI], AX
LOOP ITER
ENDS
DATA SEGMENT
DB * DUP (0)
ARRAY DB 0B9H,8BH,01H,70H,02H,06H,34H,0CH
ENDS
END START
Note: Replace * in the above code with the last digit of your student ID. NO credit will be given if you don’t replace it with a proper number.
Enter the above program in emu8086, obtain the list file and single step the program, to complete tasks and answer questions below.
• Fill in the blanks in the following table after each instruction is executed for the first run of the ITER loop: (3 marks)
Run 1
AX
CX
SI
8-bit data in DS:SI
8-bit data in DS:SI+1
MOV AX, [SI]
XCHG AH, AL
ROL AX, 1
INC SI
AND [SI], AX
LOOP ITER
The data of the 8 memory locations starting from ARRAY at the end of Run 1:
What is the function of ROL? Use the numbers in ROL AX,1 to explain. (1 mark)
What is the function of AND? (1 mark)
• Fill in the blanks in the following table after each instruction is executed for the second run of the ITER loop: (3 marks)
Run 2
AX
CX
SI
8-bit data in DS:SI
8-bit data in DS:SI+1
MOV AX, [SI]
XCHG AH, AL
ROL AX, 1
INC SI
AND [SI], AX
LOOP ITER
The data of the 8 memory locations starting from ARRAY at the end of Run 2:
What are the final values of them after the execution of the program? Explanation and screenshot are required. (3 marks)
• If the data transferred into CX is 6, how many times will the LOOP instruction execute? (1 mark)
Write an equivalent instruction to MOV AX,DATA using array. (3 marks)
19. Type the following program in emu8086 .exe file and single step it. (5 marks)
CODE_SEG SEGMENT
EX610 PROC FAR
PUSH DS
MOV AX,0
PUSH AX
CALL SUM
RETF
ENDP
SUM PROC NEAR
MOV DX,AX
ADD AX,BX
RET
ENDP
ENDS
END EX610
Fill in the white blanks in the following table after each instruction is executed
SP
CS
IP
8-bit data in SS:SP
8-bit data in SS:SP+1
PUSH DS
PUSH AX
CALL SUM
RET
RETF
20. Write an asm file to add two numbers and display the sum on the screen. You need to make sure that the two numbers are small such that the sum is no more than 9. Your program should be FULLY functioning to gain credit.
Screenshots are not required. (5 marks)
21. Type the following program in an emu8086 .com file and run it to test its function.
(15 marks)
#start=simple.exe#
#make_bin#
name “simpleio”
; write byte value 0A7h into the port 110:
MOV AL, 0A7H
OUT 110, AL
; write word value 1234h into the port 112:
MOV AX, 1234H
OUT 112, AX
MOV AX, 0 ; reset register.
; read byte from port 110 into AL:
IN AL, 110
; read word from port 112 into AX:
IN AX, 112
HLT
After clicking on the “run” button, the program, a vitual IO device will be setup as shown below.
Now you can type a byte number in the top window and type a word number in the following window. They are displayed in the bottom two windows by emu8086. In the program, they are also read into registers. Please check which registers they are saved. (You can also save them to memory.)
Modify the above program to implement a polling scheme. The scheme tests (1) whether a port has a new number entered and (2) if there is a new number entered in a port, displays a corresponding notification message. To gain credit for this question, your group program should be fully functioning.
22. In lab 4, you learned how to use INT 21H function to obtain the hour and minute values of the current time. In a previous tutorial, you also learned about how to send a beep sound to the computer speaker also shown below. The task of this question is to implement an alarm. A continuous beep sound is generated when the system time reaches a pre-set one. The pre-set time can be stored in a register (registers). To gain credit for this question, your group program should be fully functioning. (15 marks)
mov ah, 02
mov dl, 07h ;07h is the value to produce the beep tone
int 21h
23. (Analysis of an assembly program) (25 marks)
This is a problem solving question and can be done in group. All members in a group can submit identical work. Each group should not have more than 3 students. In your submission, please clearly state your group members.
For this question, the lecturer won’t give solutions. Your group should seek continuous guidance/advice from the lecturer via email and face-to-face consultation.
All students must attend lecture and their registered tutorial classes on 27 January, Wednesday of week 13, to present their work in lecture or tutorial class using powerpoint slides. No credit will be given for this question without oral presentation.
The powerpoint slides should be submitted to the Assignment 2 Oral Presentation submission link by 5:00pm of 22 January, Friday of week 12, so that the Lecturer can upload them beforehand.
The presentation schedule will be announced at 10:00 am, 23 January, Saturday of week 12.
The main program of snake-qc.asm contains four blocks: show new head, erase the old tail, check for esc key, stop the game. In lines 159 -204, there is one subroutine move the snake to shift the coordinates of each parts of the snake to right by one position.
Open the uploaded assembly program snake-qc.asm using emu8086. Execute the program to help you understand its function and ensure that you understand the functions of individual instructions and are able to find those four blocks and one subroutine.
Task 1: Each group should draw a flowchart of the main program. The flowchart should contain rectangular boxes for the aforementioned four blocks and one subroutine, and diamond boxes with branches and associated conditions (e.g., how a subroutine jumps back to the main program).
Task 2: In addition to the flowchart for the program, answer the following questions:
What is the 20-bit address of the memory location used to store cur_dir? (Screenshot is required to justify your answer.)
What are the 20-bit addresses of the memory locations used to store the coordinates of the head of the snake?
When the snake is moving, if a key, other than any of the four direction keys and ESC key, is pressed, the snake stops moving. Explain how to overcome this problem. (3 out of 25 marks)
Task 3: Each group should draw a flowchart of the move_snake procedure.
For the left movement and right movement, what changes should be made to restrict the range between column 0 and column 49h. (3 out of 25 marks)
DOS/BIOS instructions used in the program:
The following two instructions ALTOGETHER move the cursor to the location with column number in DL and row number in DH.
MOV AH, 02H
INT 10H
The following four instructions ALTOGETHER print a character stored in ALat the current cursor location and advance the current cursor position.
MOV AL, ‘ ‘
MOV AH, 09H
MOV CX, 1 ; single char.
INT 10H
The following two instructions ALTOGETHER check for keypress in the keyboard buffer. ZF=1 if no key is pressed.
MOV AH, 01H
INT 16H
The following two instructions ALTOGETHER read a character from keyboard into AH with NO echo on screen. If no key is pressed, the processor keeps waiting for a key.
MOV AH, 00H
INT 16H
Questions 21-23 can be done in groups. All members in a group can submit the same explanations/solutions. Each group should have no more than 3 students.
Notes:
• For Question 18, * is the last digit of your student ID. NO credit will be given if you don’t replace it with a proper number.
• The last 2 questions are challenging ones. No detailed advice will be provided.
• For Questions 17-20, when starting emu8086, make sure that 1. choose .exe file, 2. Only copy or insert instructions INSIDE the data segment and code segment in the given template and 3. always keep an address label “start” at the beginning of the first instruction.
• After emulation, if your program can not be seen in the emulator or you end up in a bin file, no credit will be given. If that happens and you cannot resolve it, please contact your lecturer immediately.
Total marks: 128
Outcomes achieved in Assignment 2 based on your submission (to be filled in by the marker)
Ques-tion
Under-standing of
arith-metic instruction
Under-standing of logic instruct-tions
Under-standing of
memory display
Under-standing of
indirect address-ing modes
Under-standing of
Ability to find data in the data segment
Ability to find segment address from the segment name
Ability to use seg and offset for an address label
Under-standing of
Ability to use and under-standing
of loop
1
√
2
√
3
√
√
√
√
4
√
5
√
6
√
7
√
8
√
9
√
10(a,b)
√
10(c)
√
√
√
11(a-d)
√
11(e)
√
√
√
12
√
13
√
14
√
15
√
√ interrupt process-ing
16
√ interrupt process-ing
17
√
√
√ Use of string instructions
18
√
√
√ list file
√
√
√
19
√ Data in the stack
√ program control
20
√
√
√
21
√ Input/output instructions
√ DOS interrupts
√
22
√ Input/output instructions
√ DOS interrupts
√