;*************************************************************
; &nbs
p;
&n
bsp; *
; &nbs
p;
MATIKA &n
bsp; *
; &nbs
p;
&n
bsp; *
;*************************************************************
;
; prekladac Asm51
;
;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;
; POZOR :
; Predpoklada ulozeni cisla v pameti od nejvyznamejsiho
bytu
; &nbs
p; k nejmene vyznamnemu bytu
; Zadana adresa udava pozici nejmene vyznamneho (posledniho)
bytu
;
;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PUBLIC SizeX,SizeY,adrX,adrY,adrZ,adrP
PUBLIC NasXYaZ,NasXYdoX,Deleni
PUBLIC CmpInt,Odmocni,Gr2Bin,Gr2BinX,Bin2Gr
mdata SEGMENT DATA
rseg mdata
SizeX: ds 1
SizeY: ds 1
adrX: ds 1
adrY: ds 1
adrZ: ds 1
adrP: ds 1
mprog SEGMENT CODE
rseg mprog
USING 0 ;?!
;***************************************************
;
; melo by to fungovat nazavisle na volbe banky registru,
; ale neoveroval jsem to
;
;***************************************************
;***************************************************
; Nasobeni cisla X (delky SizeX)
; cislem Y (delky
SizeY)
; a pricteni vysledku k cislu
Z
;**************************
; Vstup : SizeX - velikost 1. cisla X v bytech
; SizeY - velikost 2. cisla Y v
bytech
; adrX - adresa 1. cisla
X
; adrY - adresa 2. cisla
Y
; adrZ - adresa vysledku
Z
;!!! adresa cisla udava vzdy adresu nejnizsiho byte, !!!
;!!! vyssi byte jsou na nizsi adrese. !!!
;
; Vystup: na adrese adrZ vysledek
; Z := Z+ X*Y
; R5 ... preteceni vysledku pres rozsah (=
SizeX+SizeY)
;
; Pouziva:
; A,B,R0..R5
;
; Modifikuje:
;
SizeX &nb
sp; !!!!!!!!!!!!!!!!!!!!!!!!!!!!
; adrX,adrZ
; **************************************************
NasXYaZ:
mov R5,#0
XYZLoop:
mov R0, adrX
mov A, @R0
mov R2, A
dec adrX
mov R0, adrZ
dec adrZ
mov R1, adrY
mov R3, SizeY
mov R4, #0
jz XYZBC
XYZNibble:
mov A, R2
mov B, @R1
dec R1
mul AB
add A, R4
xch A, B
addc A, #0
xch A, B
add A, @R0
mov @R0, A
dec R0
mov A, B
addc A, #0
mov R4, A
djnz R3, XYZNibble
mov R3, SizeX
mov A, R4
XYZCB1:
add A, @R0
mov @R0, A
dec R0
jnc XYZBC
mov A, #1
djnz R3, XYZCB1
inc R5
XYZBC:
djnz SizeX, XYZLoop
Ret
;***************************************************
; Nasobeni cisla X (delky SizeX)
; cislem Y (delky
SizeY)
; ulozeni vysledku
na pozici cisla X
;**************************
; Vstup : SizeX - velikost 1. cisla X v bytech
; SizeY - velikost 2. cisla Y v
bytech
; adrX - adresa 1. cisla
X
; adrY - adresa 2. cisla
Y
;
; Vystup: na adrese adrZ vysledek
; X := X*Y
;
; Pouziva:
; A,B,R0..R4
;
; Modifikuje:
;
SizeX &nb
sp; !!!!!!!!!!!!!!!!!!!!!!!!!!!!
; AdrZ
; **************************************************
NasXYdoX:
CLR C
Mov A,adrX
Subb A,SizeX
mov R0,A
Add A,#1
Mov adrX,A
mov R1,SizeY
XYmaz:
mov @R0,#0
dec R0
Djnz R1,XYmaz
MOV AdrZ,#1
XYLoop:
mov R0, adrX
inc adrX
mov A, @R0
mov R2, A
mov @R0,#0
mov R1, adrY
mov R3, SizeY
mov R4, #0
jz XYBC
XYNibble:
mov A, R2
mov B, @R1
dec R1
mul AB
add A, R4
xch A, B
addc A, #0
xch A, B
add A, @R0
mov @R0, A
dec R0
mov A, B
addc A, #0
mov R4, A
djnz R3, XYNibble
mov R3, AdrZ
mov A, R4
XYCB1:
add A, @R0
mov @R0, A
dec R0
jnc XYBC
mov A, #1
djnz R3, XYCB1
XYBC:
INC AdrZ
djnz SizeX, XYLoop
Ret
;**************************************************
; **** Deleni X bytovym cislem X bytove cislo *****
;
; Vstup : adrX .... delenec
; adrY .... delitel
; SizeX ...... velikost cisel v
Bytech (jsou stejne)
; adrP .... pomocna
; adrZ .... zbytek
;
; Vystup: na adrX .... podil
; na adrZ .... zbytek -
po uprave
;
; Pouziva:
; A,B, R0..R3
; adrP ... pomocne cislo
velikosti SizeX
;
; dopocitani zbytku samostatna procedura
; **************************************************
Deleni:
mov A,SizeX
mov B,#8
mul AB
add A,#1
mov R3,A ; pocet
bitu + 1
mov r0,adrZ
mov R2,SizeX
DelMaz:
mov @r0,#0
dec r0
djnz R2,DelMaz
Del1:
mov r0,adrZ
mov r1,adrP
mov R2,SizeX
Dcopy1:
mov
A,@R0
mov @R1,A
dec R0
dec R1
djnz R2,Dcopy1
CLR C
&nbs
p; ; z := z - y
mov r0,adrZ
mov r1,adrY
mov R2,SizeX
DSub1:
mov
A,@R0
subb A,@R1
mov @R0,A
dec R0
dec R1
djnz R2,DSub1
JNC
Del2
mov r0,adrP
mov r1,adrZ
mov R2,SizeX
Dcopy2:
mov
A,@R0
mov @R1,A
dec R0
dec R1
djnz R2,Dcopy2
Del2:
CPL C
mov R0,adrX
mov R2,SizeX
DelRol1:
mov
A,@R0
rlc A
mov @R0,A
dec R0
djnz R2,DelRol1
mov R0,adrZ
mov R2,SizeX
DelRol2:
mov
A,@R0
rlc A
mov @R0,A
dec R0
djnz R2,DelRol2
DJNZ
R3,Del1
RET
;****************************************
; uprava pro spravny zbytek pri deleni
;****************************************
Zbytek:
mov R0,adrZ
mov R2,SizeX
CLR C
ZbyRol:
mov
A,@R0
rrc A
mov @R0,A
dec R0
djnz R2,ZbyRol
RET
;****************************************
;
; Porovnani dvou cisel se znamenkem (integer)
;
; Vstup : R0,R1 .... adresy cisel
; SizeX .... velikost cisel v
Bytech
;
; Pouziva: R2,A,B
;
; Vystup:
;
R2<>0 => @R0 <> @R1
; C = 1
=> @R0 < @R1
;****************************************
CmpInt:
MOV R2,SizeX
MOV
A,@R0 ; byte se znamenkem
CPL Acc.7
MOV B,A
MOV A,@R1
CPL Acc.7
CJNE A,B,CmpIntRet
DEC R2
CmpIntCykl:
INC
R0 ; dalsi byty
INC R1
MOV A,@R0
MOV B,A
MOV A,@R1
CJNE A,B,CmpIntRet
DJNZ R2,CmpIntCykl
CmpIntRet:
RET
;**************************************************************************
;
; Vypocet odmocniny
;
;****************************************
; zadani adrX .... adresa cisla
; SizeX.... velikost
cisla v bytech
; SizeY.... velikost
vysledku (SizeX /2 + 1)
; adrY .... adresa
vysledku
; adrZ .... adresa
pomocneho cisla 1
; adrP .... adresa
pomocneho cisla 2
; &nbs
p; velikost Z,P = SizeY
;**************************************************************************
odmocni:
MOV
R0,adrY
MOV
R1,SizeY
oYmaz:
MOV
@R0,#0
DEC
R0
DJNZ
R1,oYmaz
MOV
R0,adrZ
MOV
R1,SizeY
oZmaz:
MOV
@R0,#0
DEC
R0
DJNZ
R1,oZmaz
MOV
A,SizeX
MOV
B,#4
MUL
AB
MOV
R3,A
oCykl:
CLR
C
MOV
R0,adrX
MOV
R1,SizeX
oXrl1:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oXrl1
MOV
R0,adrZ
MOV
R1,SizeY
oZrl1:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oZrl1
MOV
R0,adrX
MOV
R1,SizeX
oXrl2:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oXrl2
MOV
R0,adrZ
MOV
R1,SizeY
oZrl2:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oZrl2
MOV
R0,adrY
MOV
R1,SizeY
oYrl1:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oYrl1
SETB
C
MOV
R0,adrY
MOV
R1,SizeY
oYrl2:
MOV
A,@R0
RLC
A
MOV
@R0,A
DEC
R0
DJNZ
R1,oYrl2
MOV
R0,adrZ
MOV
R1,adrP
MOV
R2,SizeY
oZdoP:
MOV
A,@R0
MOV
@R1,A
DEC
R0
DEC
R1
DJNZ
R2,oZdoP
MOV
R0,adrZ
MOV
R1,adrY
MOV
R2,SizeY
CLR
C
oZbezY:
MOV
A,@R0
SUBB
A,@R1
MOV
@R0,A
DEC
R0
DEC
R1
DJNZ
R2,oZbezY
JNC
oAdd1
MOV
R0,adrP
MOV
R1,adrZ
MOV
R2,SizeY
oPdoZ:
MOV
A,@R0
MOV
@R1,A
DEC
R0
DEC
R1
DJNZ
R2,oPdoZ
CLR
C
MOV
A,adrY
SUBB
A,SizeY
MOV
R0,A
MOV
R1,SizeY
oYrr0:
INC
R0
MOV
A,@R0
RRC
A
MOV
@R0,A
DJNZ
R1,oYrr0
JMP
oCend
oAdd1:
CLR
C
MOV
A,adrY
SUBB
A,SizeY
MOV
R0,A
MOV
R1,SizeY
oYrr1:
INC
R0
MOV
A,@R0
RRC
A
MOV
@R0,A
DJNZ
R1,oYrr1
SETB
Acc.0
MOV
@R0,A
oCend:
DJNZ
R3,oCyklz
JMP
odmret
oCyklz:
JMP
oCykl
odmret:
Ret
;*****************************************************
;* prevod Grayova kodu na Binarni
kod *
;* vstup ...
acc  
; *
;* ( v R2
lze omezit pocet bitu (2..8)) *
;* ( a potom volat
gr2binx )
*
;* vysledek ...
acc  
; *
;*****************************************************
;
gr2bin:
MOV R2,#8
gr2binX:
MOV B,A
grcyk:
CLR C
XCH
A,B ; rot B ->
RRC A
XCH A,B
XRL
A,B ; XOR A,B
DJNZ R2,grcyk
RET
;*****************************************************
;* prevod Binarniho kodu na GRAYuv
kod *
;* vstup ...
acc  
; *
;* vysledek ...
acc  
; *
;*****************************************************
;
bin2gr:
MOV
B,A
CLR
C
RRC
A
XRL
A,B
RET
;******************************
end
; konec souboru matika.asm
|