From 5df325b75fc74a661aad609b384e3a72ccd9cbad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sude=20=C3=87akmak?= Date: Fri, 25 Nov 2022 01:43:50 +0300 Subject: [PATCH] Function calls and indirect addressing --- .../152120201044.asm | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 Function calls and indirect addressing/152120201044.asm diff --git a/Function calls and indirect addressing/152120201044.asm b/Function calls and indirect addressing/152120201044.asm new file mode 100644 index 0000000..97ada14 --- /dev/null +++ b/Function calls and indirect addressing/152120201044.asm @@ -0,0 +1,240 @@ + LIST P=16F877A + INCLUDE P16F877.INC + __CONFIG _CP_OFF &_WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF + radix dec + + ; Reset vector + org 0x00 + ; ---------- Initialization --------------------------------- + BSF STATUS, RP0 ; Select Bank1 + CLRF TRISB ; Set all pins of PORTB as output + CLRF TRISD ; Set all pins of PORTD as output + BCF STATUS, RP0 ; Select Bank0 + CLRF PORTB ; Turn off all LEDs connected to PORTB + CLRF PORTD ; Turn off all LEDs connected to PORTD + + ; ---------- Your code starts here -------------------------- + + x EQU 0x20 + y EQU 0X21 + N EQU 0X22 + sum EQU 0X23 + R_L EQU 0x24 ; Low byte of the result + R_H EQU 0x25 ; High byte of the result. R = X * Y + temp EQU 0x26 + count EQU 0x27 + Rem EQU 0x28 + Q EQU 0x29 + A EQU 0x32 + + MOVLW A + MOVWF FSR ; FSR = &A[0] + + +main: + + MOVLW 112 + MOVWF x + MOVLW 100 + MOVWF y + MOVLW 125 + MOVWF N + + + CALL GenerateNumbers + CALL AddNumbers + CALL DisplayNumbers + GOTO finish + + ;x*y +Multiply: + COUNT EQU 0x70 + CLRF COUNT ; COUNT = 0 + BSF COUNT, 3 ; COUNT = 8 + CLRF R_H ; R_H = 0 + MOVFW y ; WREG = y (Multiplier) + MOVWF R_L ; R_L = WREG + MOVFW x ; WREG = x (Multiplicant) + RRF R_L, F ; R_L = R_L >> 1 +Mult8x8_Loop: + BTFSC STATUS, C ; Is the least significant bit of Y equal to 1? + ADDWF R_H, F ; R_H = R_H + WREG + RRF R_H, F ; R_H = R_H >> 1 + RRF R_L, F ; R_L = R_L >> 1 + + DECFSZ COUNT ; COUNT = COUNT-1 + GOTO Mult8x8_Loop + RETURN ; DONE + + ;temp/3 +Division: + Counter EQU 0x71 + MOVLW 8 + MOVWF Counter + CLRF Rem + MOVF temp, W + MOVWF Q +process: + BCF STATUS, C + RLF Q, F + RLF Rem, F + MOVLW 3 + SUBWF Rem, W + BTFSS STATUS, C + GOTO countdown + BSF Q, 0 + MOVWF Rem +countdown: + DECFSZ Counter, F + GOTO process + RETURN + + +GenerateNumbers: + ;y