0% found this document useful (0 votes)
101 views

Answer Sheet # 2 Microcontroller and Applications

This document contains a worksheet for a class on PIC microcontroller architecture and assembly language programming. It includes multiple choice and true/false questions about PIC registers, memory spaces, instruction sets, and RISC vs CISC architectures. It also provides examples of PIC assembly code instructions and exercises for students to write simple programs manipulating data in registers and memory locations.

Uploaded by

Mahmoud salah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Answer Sheet # 2 Microcontroller and Applications

This document contains a worksheet for a class on PIC microcontroller architecture and assembly language programming. It includes multiple choice and true/false questions about PIC registers, memory spaces, instruction sets, and RISC vs CISC architectures. It also provides examples of PIC assembly code instructions and exercises for students to write simple programs manipulating data in registers and memory locations.

Uploaded by

Mahmoud salah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Horus University in Egypt Microcontroller and

(HUE) Faculty of Applications


Engineering Mechatronics (ECE 442)
Department

Sheet # 2
Chapter # 2: PIC ARCHITECTURE & ASSEMBLY LANGUAGE ROGRAMMING

Q1: Complete the following:

1. Register WREG is 8 bits wide.

2. The literal value in MOVLW is 8 bits wide.

3. The largest number that can be loaded into WREG is FF in hex and decimal equivalent 255.

4. To load WREG with the value 65H, the pound sign is -------- (not necessary, optional, necessary)
in the instruction "MOVLW 6 5 H".

5. The largest number that K can take for the instruction “ADDWL K” is FF in hex.

6. PIC data RAM consists of -------- (EEPROM, SRAM).

7. If we add the SFR and general-purpose RAM sizes together we should get the total space for the -
File registers

8. The vast majority of registers in the PIC are 8 bit.

9. The SFR registers in PIC are 8 bit.

10. The file register space in PIC18 is divided into 256-byte banks.

11. The file register space in PIC18 can be a maximum of 4096 bytes.

12. “ADDWF PORTB, W” puts the result in WREG, The flag register in the PIC is called the
STATUS Register

13. The “ADDWF fileReg, D” instruction to place the result in WREG, the D bit must be 0.

14. The “ADDWF fileReg, D” instruction to place the result in fileReg, the D bit must be 1.

15. RISC processors normally have a ------------ (large, small) number of general-purpose registers.
16. Pseudo-instructions are also called Directives.
17. The access bank has -256 bytes space.
18. The maximum number of banks that the PIC18 can have 256 and the maximum number of bytes
that the PIC18 can have for the File register 16 banks.

1
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

19. The file provides the listing of error messages “.err “.

20. The size of the flag register in the PIC is 8 and 3 are unused.

21. The largest hex value that can be moved into a location in the file register FF, is the decimal
equivalent value 255.
22. Which of the following instructions produces opcode? -------- List all that do.
(a) MOVLW 25H (b) ADDLW 12 (c) ORG 2000H (d) GOTO HERE
22. The file with the “.hex “ extension is downloaded into PIC ROM.
Q:3 True or False
1. Assembler directives are not used by the CPU itself. They are simply a guide to the assembler. True

2. No value can be moved directly into the WREG register. False

5. We have many WREG registers in the PIC18. False

3. Data RAM in PIC is also called the file register. True

4. The larger the file register, the more difficult it is to manage. True

5. No value can be moved directly into general-purpose RAM. True

6. Instructions such as “ADD WREG, ROM memory” do not exist in RISC microcontrollers such as
the PIC18. True

7. While CISC instructions are of variable sizes, RISC instructions are all the same size. True

8. Harvard architecture uses the same address and data buses to fetch both code and data. False

7. All members of PIC18 family have the same size file register. False

9. The SFRs are part of the file register memory space. True

5. The general-purpose RAM is not part of the file register memory space. False

10. The more file register space that is assigned to the SFRs, the less is available for the GP RAM. True

11. The access bank is 256 bytes divided evenly between GPRs and SFRs. True

12. The source file has the extension "asm". True


13. We cannot load literal values into the scratch pad area directly. True
2
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

14. We can use MOVFF to copy data from any location to any location in the file register. False

15. The source code file can be a non-ASCII file. False

16. Every source file must have ORG and END directives. True

17. The ORG and END directives appear in the ".1st" file. False

18. The linker produces the file with the extension "asm". False

19. The linker produces the file with the extension "hex". True

20. The “ADDWF fileReg, D” instruction involves a fileReg and WREG. True
Q3: Answer:

1. Find the C, Z, and DC flag bits for the following code:


(a) MOVLW 9F H (b) MOVLW 82H
ADDLW 6l H ADDLW 22H

(c) MOVLW 67H (d) MOVLW FFH


ADDLW 99H ADDLW l

(a) 9F H 1001 1111 C=1 OV = 0


6l H 0110 0001 Z=1 N=0
0000 0000 DC = 1

(b) 82 H 1000 0010 C=0 OV = 0


22 H 0010 0010 Z=0 N=1
1010 0100 DC = 0

(c) 67 H 1001 1111 C=1 OV = 0


99 H 0110 0001 Z=1 N=0
0000 0000 DC =1

(d) FF H 1001 1111 C=1 OV = 0


0l H 0110 0001 Z=1 N=0
0000 0000 DC = 1

3
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

2. Give the value in fileReg 0x20 for the following:


MYCOUNT EQU 0x95 WREG = 95 H
MYREG EQU Dx20 MYREG (fileReg 0x20) = 95 H
MOVLW MYCOUNT
MOVWF MYREG

3. Give the value in fileReg 0x63 for the following:


MYDATA EQU D'12'
MYREG EQU 0x63
FACTOR EQU 0xl0
MOVLW MYDATA WREG = 0C H
ADDLW FACTOR W = 0C + 10 = 1C H
MOVWF MYREG MYREG (fileReg 0x63) = 1C H

4. Write instructions to add the values l6H and CDH, Place the result in the WREG register.
MOVLW 0x16
ADDLW 0XCD

5. Show a simple code to load value l5H into location 7, and add it to WREG five times and
place the result in WREG as the values are added. WREG should be zero before the addition
starts.
MOVLW 0x15
MOVWF LOCATION_7
MOVLW 00
ADDWF LOCATION_7, W
ADDWF LOCATION_7, W
ADDWF LOCATION_7, W
ADDWF LOCATION_7, W
ADDWF LOCATION_7, W

6. Show a simple code to load values 30H and 97H into locations 5 and 6 respectively.
MOVLW 0X30
MOVWF LOCATION_5
MOVLW 0X97
MOVWF LOCATION_6

4
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

7. Show how to represent decimal 99 in formats of


(a) hex (in three ways), (b) decimal, and (c) binary in the PIC assembler.

(a)MOVLW 0x63 (b)MOVLW D ’99’ (c) MOVLW B’01100011’


MOVLW 63 H
MOVLW 63

8. Compare between RISC and CISC? And each one stand for?

RISC CISC

Reduced Instruction Set Computer Complex Instruction Set Computer

Simple and Small instruction Complex and large instruction set

Regular and fixed instruction format Irregular instruction format

Simple address modes Set Complex address modes Set

Pipelined instruction execution -->95%


May also pipeline instruction execution
executed in one cycle

Provide smaller number of CPU Most


Provide large number of CPU registers
operations

Registers Combined data and program


Separated data and program memory
memory

Most operations are register to register can be register to memory

Take shorter time to design and debug Take longer time to design and debug

5
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

9. Find the address of the last location of on-chip program ROM for each of the following:
(a) PIC with 48 KB
48 * 1024 = 49152 ( in decimal convert to hexadecimal ) = C000
To find the last address C000 – 0001 = BFFF
ROM address rang 0000 – BFFF.

(c) PIC with 64 KB


64 * 1024 = 65536 ------- to hex = 10000
Last address = 10000 – 1 = 0FFFF
ROM address rang 00000 – 0FFFF.

(f) PIC with 128 KB


128 * 1024 = 131072 ------- to hex = 20000
Last address = 20000 – 1 = 1FFFF
ROM address rang 00000 – 1FFFF.
Another solution:
128 K = 27 * 210 = 217 =21 * 216
0 .0000.0000.0000.0000
1 .FFFF.FFFF.FFFF.FFFF
(b) PIC with 96 KB
96 * 1024 = 98304 ------- to hex = 18000
Last address = 18000 – 1 = 17FFF
ROM address rang 00000 – 17FFF.

(d) PIC with 16 KB


16 * 1024 = 16384 ------- to hex = 4000
Last address = 4000 – 1 = 3FFF
ROM address rang 0000 – 3FFF.

6
Horus University in Egypt Microcontroller and
(HUE) Faculty of Applications
Engineering Mechatronics (ECE 442)
Department

10.Find the on-chip program ROM size in K for the PIC18 with the followingaddress ranges:
(a) 00000 - 4FFFF (b) 00000 - 3FFFF
(c) 00000 - 5FFFF (d) 00000 - 7FFFF
(e) 00000 - BFFFF (f) 00000 - FFFFF
(g) 00000 - l7FFFF (h) 00000 - 1FFFFF

(a) 00000 – 4FFFF


4FFFF + 1 = 50000 ----------- Convert to decimal = 327680 / 1024 = 320 KB
(b) 00000 – 3FFFF
3FFFF + 1 = 40000 ----------- Convert to decimal = 262144/ 1024 = 256 KB
(c) 00000 – 5FFFF
5FFFF + 1 = 60000 ----------- Convert to decimal = 393216/ 1024 = 384 KB
(d) 00000 – 7FFFF
7FFFF + 1 = 80000 ----------- Convert to decimal = 524288/ 1024 = 512 KB
(e) 00000 – BFFFF
BFFFF + 1 = C0000 ----------- Convert to decimal = 786432 / 1024 = 768 KB
(f) 00000 – FFFFF
FFFFF + 1 = 100000 ------- Convert to decimal = 1048576/ 1024 = 1024 KB = 1 MB
(g) 00000 – 17FFFF
17FFFF + 1 = 180000 ---- Convert to decimal = 1572864/ 1024 = 1536 KB = 1.5 MB
(h) 000000 – 1FFFFF
1FFFFF + 1 = 200000 ------ Convert to decimal = 2097152/ 1024 = 2048 KB = 2 MB

You might also like