From 912b6048a7603a9fcf65f02d84dfe5679419f0ea Mon Sep 17 00:00:00 2001 From: minniewang12 <137521170+minniewang12@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:14:03 +0000 Subject: [PATCH 1/2] Division subroutine --- main.s | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/main.s b/main.s index 2ac9cc7c..b34059c1 100755 --- a/main.s +++ b/main.s @@ -1,6 +1,13 @@ - #include +#include psect code, abs + +psect udata_ +myNumerator:ds 1 +myDenominator:ds 1 +myQuotient:ds 1 +myRemainder:ds 1 +myDiff:ds 1 main: org 0x0 @@ -9,16 +16,70 @@ main: org 0x100 ; Main code starts here at address 0x100 start: movlw 0x0 - movwf TRISB, A ; Port C all outputs + movwf TRISC, A ; Port C all outputs bra test loop: - movff 0x06, PORTB + movff 0x06, PORTC incf 0x06, W, A test: movwf 0x06, A ; Test for end of loop condition - movlw 0x63 + movlw 0x01 cpfsgt 0x06, A bra loop ; Not yet finished goto start of loop again - goto 0x0 ; Re-run program from start + ;goto 0x0 ; Re-run program from start + +; PIC18 Assembly division example + +; Inputs: +; Numerator in WREG +; Denominator in a register (e.g., myDenominator) + + ; Initialize variables + MOVLW 11 ; Numerator + MOVWF myNumerator + + MOVLW 3 ; Denominator + MOVWF myDenominator + + ; Perform division + CALL Divide + ; Result is now in WREG + + ; Your code here + +Divide: + ; Ensure myDenominator is not zero + MOVLW 0 + CPFSEQ myDenominator + GOTO Clear ; Check the MSB of myDenominator + GOTO DivisionError ; If zero, handle division by zero +Clear: ; Perform division algorithm + CLRF myQuotient ; Clear the quotient register + CLRF myRemainder ; Clear the remainder register + +DivideLoop: + MOVFF myNumerator, WREG + + ; rather than doing subtraction, just do a comparison + CPFSGT myDenominator ; myNumerator(WREG) < myDenominator, skip to finish + GOTO Incr + GOTO DivisionDone ; Done if myNumerator < myDenominator +Incr: + INCF myQuotient, 1 ; Increment quotient + MOVFF myDenominator, WREG + SUBWF myNumerator, 1 ; myNumerator -= myDenominator + GOTO DivideLoop ; Repeat the loop + +DivisionDone: + ; Quotient is in myQuotient, remainder is in myRemainder + MOVFF myQuotient, PORTC + RETURN + +DivisionError: + ; Handle division by zero or other error + ; Your code here + RETURN + end main + From 32bccebb456c402f0b8af364c702d6b61734755a Mon Sep 17 00:00:00 2001 From: minniewang12 <137521170+minniewang12@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:14:38 +0000 Subject: [PATCH 2/2] Update configurations.xml --- nbproject/configurations.xml | 199 ++++++++++++++++------------------- 1 file changed, 92 insertions(+), 107 deletions(-) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 9ba40ccd..ec4baff3 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -12,8 +12,13 @@ - main.s config.s + main.s + UART.s + LCD.s + Keypad.s + Digit_Reader.s + Calculations.s Simulator pic-as - 2.41 - 3 + 2.45 + 4 @@ -64,86 +69,50 @@ false false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -619,14 +588,35 @@ + + + + + + + + + + + + + + + + + + + @@ -645,6 +635,21 @@ + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - @@ -1134,14 +1118,15 @@ - + + - +