SlideShare a Scribd company logo
1 of 9
Download to read offline
ECE 3724/CS 3124 Test #2 – Summer 2005- Reese

You may NOT use a calculator. You may use only the provided reference materials. If a
binary result is required, give the value in HEX. Assume all variables are in the first 128
locations of bank 0 (access bank) unless stated otherwise.

Part I: (82 pts)

a. (6 pts) Write a PIC18 assembly code fragment to implement the following.

       signed int i, k;

       i = k << 1;




b. (8 pts) Write a PIC18 assembly code fragment to implement the following. The code
   of the if{} body has been left intentionally blank; I am only interested in the
   comparison test. For the if{} body code, just use a couple of dummy instructions so I
   can see the start/begin of the if{} body.


       int i, k;

       if (i == k) {
          ..operation 1...
          ..operation 2....
       }
c. (6 pts) Write a PIC18 assembly code fragment to implement the following:
       signed char j, k;
                                        loop_top:
                                             movf       ___,w
                                             _____      ___,w
        while ( k >= j) {                    b____      L1
           operation 1...                    b____      loop_body ;if true, loop body
           operation 2...                    bra        loop_exit ;exit
          }                             L1
                                             b____      loop_exit ;if false, exit
                                        loop_body:
                                             ...code for operation 1...
                                             ...code for operation 2....
                                        loop_exit
                                             ....rest of code....




d.    ( 8 pts) Implement the doshift subroutine in PIC18 assembly language. Assume the
     value of ptr has been passed in the FSR0 register by the calling subroutine. Do not
     forget that this is a subroutine!!!!!!

// shift function
doshift (unsigned int *ptr){

      *ptr = (*ptr) >> 1;

}
e. (9 pts) Implement the main() code below in PIC assembly. You MUST pass the
   parameters for the a_sub() function using the CBLOCK locations for the function
   a_sub(). You CANNOT just use FSR0 for passing the ptr value to a_sub().


   a_sub (char c, long *ptr){              CBLOCK 0x040       // parm. block for a_sub
   // some code ...... //                   c: 1, ptr: 2
                                           ENDC
   }

   main() {                                CBLOCK 0x060 // parm. block for main
   char p;                                 // define p, k space here, fill in blanks
   long k;                                 p: ____, k: ______
   // some code that initializes
   // p, k ....., don’t worry about this
   //now, call a_sub() function            ENDC

   a_sub( p, &k);
   }




f. (8 pts) Write a PIC18 assembly code fragment to implement the following. The code
   of the if{} body has been left intentionally blank; I am only interested in the
   comparison test. For the if{} body code, just use a couple of dummy instructions so I
   can see the start/begin of the if{} body.


       int i, k;

       if ((i == 0) && (k != 0) ) {
          ..operation 1...
          ..operation 2....
       }
g. (6 pts) Write a PIC18 assembly code fragment to implement the following:


       long p, q;

       p =    p - q;
h. (15 pts)
After the execution of ALL of the C code below, fill in the memory location values.
Assume little-endian order for multi-byte values.
CBLOCK 0x0150
r:2, t:4, s:1, ptra:2, ptrb:2
ENDC
C code:
unsigned int r;
signed long t;           // this is SIGNED!!!!!!!
signed char s;            // this is SIGNED!!!!!!!
signed char *ptra;
unsigned int *ptrb;
r = 256;               // specified in decimal!!    (3 pts)
t = -2;               // specified in decimal!!     ( 3 pts)
s = -49;              // specified in decimal!!!! (3 pts)
ptra = &s;                                         (3 pts)
ptrb = &r;
ptrb++;                                            (3 pts)

Location            Contents (MUST BE GIVEN IN HEX!!!!)

0x0150            ___________

0x0151            ___________

0x0152            ___________

0x0153            ___________

0x0154            ___________

0x0155            ___________

0x0156            ___________

0x0157            ___________

0x0158            ___________

0x0159            ___________

0x015A            ___________
i. (16 pts)

For each of the following problems, give the FINAL contents of changed registers or
memory locations. Give me the actual ADDRESSES for a changed memory location (e.g.
Location 0x0100 = 0x??). Assume these memory/register contents at the BEGINNING of
EACH problem!!!

Memory:                                   W register = 0x03
0x0100         0x45
0x0101         0xFF
0x0102         0xBA
0x0103         0x3C
0x0104         0x64

j. (4 pts)
                                                    FSR1 = ____________
               lfsr           FSR1, 0x0101
               movff          PREINC1,0x0100
                                                    Location ________ = _________

k. (4 pts)

                                                  FSR1 = ____________
               lfsr           FSR1, 0x0100
               movff          PLUSW1, 0x0100
                                                  Location ________ = _________



l.   (4 pts)
                                                    FSR1 = ____________
               lfsr           FSR1, 0x0103
               movff          POSTDEC1,0x100
                                                    Location ________ = _________



m. (4 pts) (careful on this one!!!!!)
                                                    FSR1 = ____________
               lfsr           FSR1, 0x0103
               movff          FSR1H,0x100
                                                    Location ________ = _________
Part II: (18 pts) Answer 6 out of the next 8 questions. Cross out the 2 questions that
you do not want graded. Each question is worth 3 pts.


   1. Fill in memory location below, and either a CALL or RCALL instruction (use
      mnemonic, not machine code) such that a value of 0x0104 is pushed as the return
      address on the stack


          Mem location                    instruction

          __________                     __________




   2. Write an 8-bit addition such that afterwards, both the V and the N flags are set.


          ____________         +        ______________           afterwards, V=1,N=1




   3. Given an N-bit number, what number range can I represent using 2’s complement
      encoding?
4. In the code below, what is the value of i when the loop is exited? Give the value
   in either hex or decimal.

 signed char i;

 i = 0x80;
 while (i <= -32) {
   i = i >> 1;
 }




5. Give the machine code for the ‘bnn 0x200’ instruction below given the locations
   shown:

           location
           0x0200                decf 0x02,f
           0x0202                ???
           0x0204                ???
           0x0206                ???
           0x0208                bnn    0x200




6. On the PIC18, can I nest subroutine calls as deep as I want? (i.e. subroutine A
   calls subroutine B calls Subroutine C calles Subroutine D ....etc). If NO, then
   why? Be detailed.
7.    Why is the width of the FSR0, FSR1, FSR2 registers different from the width of
     registers like the WREG and general purpose registers in the data memory?




8. Why can’t subroutine calls just be implemented with GOTO statements? What is
   the special feature of CALL/RETURN instructions that is absolutely essential to
   implementing subroutines?

More Related Content

What's hot

2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
웅식 전
 
Rx: Curing Your Asynchronous Programming Blues | QCon London
Rx: Curing Your Asynchronous Programming Blues |  QCon LondonRx: Curing Your Asynchronous Programming Blues |  QCon London
Rx: Curing Your Asynchronous Programming Blues | QCon London
Jiby John
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
Hackito Ergo Sum
 
เขียนโปรแกรมใช้คำสั่ง Printf scanf
เขียนโปรแกรมใช้คำสั่ง  Printf scanfเขียนโปรแกรมใช้คำสั่ง  Printf scanf
เขียนโปรแกรมใช้คำสั่ง Printf scanf
ธงชัย พาศรี
 

What's hot (20)

OpenGL ES 3 Reference Card
OpenGL ES 3 Reference CardOpenGL ES 3 Reference Card
OpenGL ES 3 Reference Card
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
 
Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Exercicios Resolvidos Série MIPS Embarcados
Exercicios Resolvidos Série MIPS EmbarcadosExercicios Resolvidos Série MIPS Embarcados
Exercicios Resolvidos Série MIPS Embarcados
 
Macro
MacroMacro
Macro
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 
Al2ed chapter18
Al2ed chapter18Al2ed chapter18
Al2ed chapter18
 
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbers
 
2 data and c
2 data and c2 data and c
2 data and c
 
Rx: Curing Your Asynchronous Programming Blues | QCon London
Rx: Curing Your Asynchronous Programming Blues |  QCon LondonRx: Curing Your Asynchronous Programming Blues |  QCon London
Rx: Curing Your Asynchronous Programming Blues | QCon London
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
 
Mips1
Mips1Mips1
Mips1
 
System software
System softwareSystem software
System software
 
เขียนโปรแกรมใช้คำสั่ง Printf scanf
เขียนโปรแกรมใช้คำสั่ง  Printf scanfเขียนโปรแกรมใช้คำสั่ง  Printf scanf
เขียนโปรแกรมใช้คำสั่ง Printf scanf
 

Viewers also liked (16)

Turtle And The Hare
Turtle And The HareTurtle And The Hare
Turtle And The Hare
 
MPITechCon Presentation on Future Trends of Meetings
MPITechCon Presentation on Future Trends of MeetingsMPITechCon Presentation on Future Trends of Meetings
MPITechCon Presentation on Future Trends of Meetings
 
1
11
1
 
Synistema e le reti sociali
Synistema e le reti socialiSynistema e le reti sociali
Synistema e le reti sociali
 
The Artist at Heart : Chapter 2.1
The Artist at Heart : Chapter 2.1The Artist at Heart : Chapter 2.1
The Artist at Heart : Chapter 2.1
 
Scott Stratten&rsquo;s Untalk 2013 at MPITechCon Feb 19, 2013
Scott Stratten&rsquo;s Untalk 2013 at MPITechCon Feb 19, 2013Scott Stratten&rsquo;s Untalk 2013 at MPITechCon Feb 19, 2013
Scott Stratten&rsquo;s Untalk 2013 at MPITechCon Feb 19, 2013
 
Presentation For Wiki
Presentation For WikiPresentation For Wiki
Presentation For Wiki
 
Coup De Beast : Chapter 1.1
Coup De Beast : Chapter 1.1Coup De Beast : Chapter 1.1
Coup De Beast : Chapter 1.1
 
Coup De Beast : Chapter 1.2
Coup De Beast : Chapter 1.2Coup De Beast : Chapter 1.2
Coup De Beast : Chapter 1.2
 
The Artist at Heart : Chapter 1
The Artist at Heart : Chapter 1The Artist at Heart : Chapter 1
The Artist at Heart : Chapter 1
 
Project – Embedded
Project – EmbeddedProject – Embedded
Project – Embedded
 
Presentation For Wiki2
Presentation For Wiki2Presentation For Wiki2
Presentation For Wiki2
 
Coup De Beast - Prologue
Coup De Beast - PrologueCoup De Beast - Prologue
Coup De Beast - Prologue
 
Coup De Beast : Prologue 2
Coup De Beast : Prologue 2Coup De Beast : Prologue 2
Coup De Beast : Prologue 2
 
La electricidad en_la_vida_cotidiana
La electricidad en_la_vida_cotidianaLa electricidad en_la_vida_cotidiana
La electricidad en_la_vida_cotidiana
 
【清新出品】中国风系列2~梅为水墨香染成.ppt
【清新出品】中国风系列2~梅为水墨香染成.ppt【清新出品】中国风系列2~梅为水墨香染成.ppt
【清新出品】中国风系列2~梅为水墨香染成.ppt
 

Similar to Test2 Sum05

EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
bolovv
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
Duoyi Wu
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
Devirtualizing FinSpy
Devirtualizing FinSpyDevirtualizing FinSpy
Devirtualizing FinSpy
jduart
 

Similar to Test2 Sum05 (20)

Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
 
Switch Control and Time Delay - Keypad
Switch Control and Time Delay - KeypadSwitch Control and Time Delay - Keypad
Switch Control and Time Delay - Keypad
 
runtimestack
runtimestackruntimestack
runtimestack
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Funções, Scanf, EOF
Funções, Scanf, EOFFunções, Scanf, EOF
Funções, Scanf, EOF
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
DEF CON 23 - Atlas - fun with symboliks
DEF CON 23 - Atlas - fun with symboliksDEF CON 23 - Atlas - fun with symboliks
DEF CON 23 - Atlas - fun with symboliks
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Debugging TV Frame 0x09
Debugging TV Frame 0x09Debugging TV Frame 0x09
Debugging TV Frame 0x09
 
Mips
MipsMips
Mips
 
Devirtualizing FinSpy
Devirtualizing FinSpyDevirtualizing FinSpy
Devirtualizing FinSpy
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 

Test2 Sum05

  • 1. ECE 3724/CS 3124 Test #2 – Summer 2005- Reese You may NOT use a calculator. You may use only the provided reference materials. If a binary result is required, give the value in HEX. Assume all variables are in the first 128 locations of bank 0 (access bank) unless stated otherwise. Part I: (82 pts) a. (6 pts) Write a PIC18 assembly code fragment to implement the following. signed int i, k; i = k << 1; b. (8 pts) Write a PIC18 assembly code fragment to implement the following. The code of the if{} body has been left intentionally blank; I am only interested in the comparison test. For the if{} body code, just use a couple of dummy instructions so I can see the start/begin of the if{} body. int i, k; if (i == k) { ..operation 1... ..operation 2.... }
  • 2. c. (6 pts) Write a PIC18 assembly code fragment to implement the following: signed char j, k; loop_top: movf ___,w _____ ___,w while ( k >= j) { b____ L1 operation 1... b____ loop_body ;if true, loop body operation 2... bra loop_exit ;exit } L1 b____ loop_exit ;if false, exit loop_body: ...code for operation 1... ...code for operation 2.... loop_exit ....rest of code.... d. ( 8 pts) Implement the doshift subroutine in PIC18 assembly language. Assume the value of ptr has been passed in the FSR0 register by the calling subroutine. Do not forget that this is a subroutine!!!!!! // shift function doshift (unsigned int *ptr){ *ptr = (*ptr) >> 1; }
  • 3. e. (9 pts) Implement the main() code below in PIC assembly. You MUST pass the parameters for the a_sub() function using the CBLOCK locations for the function a_sub(). You CANNOT just use FSR0 for passing the ptr value to a_sub(). a_sub (char c, long *ptr){ CBLOCK 0x040 // parm. block for a_sub // some code ...... // c: 1, ptr: 2 ENDC } main() { CBLOCK 0x060 // parm. block for main char p; // define p, k space here, fill in blanks long k; p: ____, k: ______ // some code that initializes // p, k ....., don’t worry about this //now, call a_sub() function ENDC a_sub( p, &k); } f. (8 pts) Write a PIC18 assembly code fragment to implement the following. The code of the if{} body has been left intentionally blank; I am only interested in the comparison test. For the if{} body code, just use a couple of dummy instructions so I can see the start/begin of the if{} body. int i, k; if ((i == 0) && (k != 0) ) { ..operation 1... ..operation 2.... }
  • 4. g. (6 pts) Write a PIC18 assembly code fragment to implement the following: long p, q; p = p - q;
  • 5. h. (15 pts) After the execution of ALL of the C code below, fill in the memory location values. Assume little-endian order for multi-byte values. CBLOCK 0x0150 r:2, t:4, s:1, ptra:2, ptrb:2 ENDC C code: unsigned int r; signed long t; // this is SIGNED!!!!!!! signed char s; // this is SIGNED!!!!!!! signed char *ptra; unsigned int *ptrb; r = 256; // specified in decimal!! (3 pts) t = -2; // specified in decimal!! ( 3 pts) s = -49; // specified in decimal!!!! (3 pts) ptra = &s; (3 pts) ptrb = &r; ptrb++; (3 pts) Location Contents (MUST BE GIVEN IN HEX!!!!) 0x0150 ___________ 0x0151 ___________ 0x0152 ___________ 0x0153 ___________ 0x0154 ___________ 0x0155 ___________ 0x0156 ___________ 0x0157 ___________ 0x0158 ___________ 0x0159 ___________ 0x015A ___________
  • 6. i. (16 pts) For each of the following problems, give the FINAL contents of changed registers or memory locations. Give me the actual ADDRESSES for a changed memory location (e.g. Location 0x0100 = 0x??). Assume these memory/register contents at the BEGINNING of EACH problem!!! Memory: W register = 0x03 0x0100 0x45 0x0101 0xFF 0x0102 0xBA 0x0103 0x3C 0x0104 0x64 j. (4 pts) FSR1 = ____________ lfsr FSR1, 0x0101 movff PREINC1,0x0100 Location ________ = _________ k. (4 pts) FSR1 = ____________ lfsr FSR1, 0x0100 movff PLUSW1, 0x0100 Location ________ = _________ l. (4 pts) FSR1 = ____________ lfsr FSR1, 0x0103 movff POSTDEC1,0x100 Location ________ = _________ m. (4 pts) (careful on this one!!!!!) FSR1 = ____________ lfsr FSR1, 0x0103 movff FSR1H,0x100 Location ________ = _________
  • 7. Part II: (18 pts) Answer 6 out of the next 8 questions. Cross out the 2 questions that you do not want graded. Each question is worth 3 pts. 1. Fill in memory location below, and either a CALL or RCALL instruction (use mnemonic, not machine code) such that a value of 0x0104 is pushed as the return address on the stack Mem location instruction __________ __________ 2. Write an 8-bit addition such that afterwards, both the V and the N flags are set. ____________ + ______________ afterwards, V=1,N=1 3. Given an N-bit number, what number range can I represent using 2’s complement encoding?
  • 8. 4. In the code below, what is the value of i when the loop is exited? Give the value in either hex or decimal. signed char i; i = 0x80; while (i <= -32) { i = i >> 1; } 5. Give the machine code for the ‘bnn 0x200’ instruction below given the locations shown: location 0x0200 decf 0x02,f 0x0202 ??? 0x0204 ??? 0x0206 ??? 0x0208 bnn 0x200 6. On the PIC18, can I nest subroutine calls as deep as I want? (i.e. subroutine A calls subroutine B calls Subroutine C calles Subroutine D ....etc). If NO, then why? Be detailed.
  • 9. 7. Why is the width of the FSR0, FSR1, FSR2 registers different from the width of registers like the WREG and general purpose registers in the data memory? 8. Why can’t subroutine calls just be implemented with GOTO statements? What is the special feature of CALL/RETURN instructions that is absolutely essential to implementing subroutines?