Lab 4: 16/32-Bit, Signed Numbers Assembly Language Programming

This lab has you convert a C program that performs 16/32-bit signed operations into PIC24 assembly language.

Basics

Be sure you do the correct case or you won't get credit for the lab.

Prelab

A label put into the case4 code. This isn't enough to get the prelab checkoff. Put in your own labels.

Task 1

Your task is to convert these C fragments to PIC24 assembly language and get 100 (0x63) PASSes.

Debugging

Before receiving help from a TA, you must:

  If you suddenly receive an "Error 255 compilation error," exit and restart MPLAB. If you continue to receive this error, close MPLAB again, hit Ctrl-Alt-Delete, and select Task Manager. Close any MPLAB tasks or processes, and restart MPLAB.

TA Checkoff

Show the TA that the values produced by your assembly language program match the C values on loop exit (i.e. you have a PASS for e:63)

Notes

W10    : W9 ; callee saved; the subroutine must preserve these register values

W0     : W1 ; wrong

W1     : W0 ; correct

i32_a+2: i32_a

W2   : W1 ; do not recommend

W7     : W6 ; best practice

W5     : W4 ; best practice

W3     : W2 ; best practice

W1     : W0 ; best practice

i32_a+2: i32_a

;       ----W5:W4----

;   MSW:LSW    MSW:LSW

;     W1:W0 W3:W2

; if (i32_k & 0x12345678) {

; Input

  mov i32_k, W0 ; LSW

  mov i32_k+2, W1 ; MSW - you can swap these first two lines, but i32_k+2 has to go into the upper register

  mov #0x1234, W3 ; MSW - see previous comment

mov #0x5678, W2 ; LSW

  

; Process

and W0, W2, W4 ; one benefit of using odd registers for MSW and even for LSW is finding bugs

and W1, W3, W5 ; you have to AND both MSW and LSW. (There is no andc. Just and and and.b)

cp W4, #0 ; don't forget these two lines

cpb W5, #0 ; cpb0 is not real

; Output

bra Z, ELSE ; if FALSE, go to ELSE:, otherwise execute the if branch

B.A. Jones, R. Reese, and JW Bruce, Microcontrollers: From Assembly Language to C Using the PIC24 Family, 2nd ed. Cengage Learning, 2015.

Report

Submit: