Hello everyone,
I write code in assembler, which subtracts two numbers. I need advice on how to modify the code subtracted from a positive number to a negative number.
For example:
826-(-621) = 1447
Thanks for you advice
; 826 = 0x33A, 961 = 3c1
; 576 = 0x240, -621 = 0x
; 978 = 0x3D2, -684 = 0x
LIST P=18F87J11
#include <P18F87J11.INC>
CONFIG FOSC = HS
CONFIG WDTEN = OFF
CONFIG XINST = OFF
udata_acs 0x000
addH res 1
cary res 1
a res 1
b res 1
c res 1
d res 1
addL res 1
prodH res 1
prodL res 1
SOUCV res 2
ORG 0x0000
goto Main ; jdi na Main
Main:
;0x33A - 0x240
movlw 0x03 ; nastav WREG na 0 hexa = 0000 0000
movwf a ; WREG => addL => addL = 0
movlw 0x3a ; nastav WREG na 0 hexa = 0000 0000
movwf b
movlw 0x02 ; nastav WREG na 0 hexa = 0000 0000
movwf c
movlw 0x40 ; nastav WREG na 0 hexa = 0000 0000
movwf d
movf d ; WREG <= 0xB8
movwf addH ; WREG => addH => 0xB8
movwf prodL
clrf SOUCV
clrf cary
subwf b
movlw 0x03
subwf a
movff b, SOUCV
movff a, SOUCV+1