mikropascal addressing through table in assembly

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
tormod
Posts: 57
Joined: 29 Nov 2004 16:31

mikropascal addressing through table in assembly

#1 Post by tormod » 10 Apr 2019 20:52

made the following function from an example on Internet to extract a single (any) byte from a dword. Using a table address method applicable to MIPS, but the compiler does not like it. It does not recognise labels nor content of the table. Tried several ways by defining a constant array. Since this has an interest in general for using table addressing I am searching for a solution that works.

function __SkrBitExtractByteFromDWord(Value : dword; Position : byte) : byte;

begin
asm
b BFDW_start
NOP
BFDW_jump:
.word BFDW_jump0
.word BFDW_JuMP1
.word BFDW_JuMP2
.word BFDW_JuMP3

BFDW_start:
lui R2,hi_addr(BFDW_jump) // get address of jump table
ori R2,R0,lo_addr(BFDW_jump)
add R2,R26,R0 // get offset and add it to R2
lw R3,0(R2) // load actual address
jr R3
NOP

BFDW_Jump0:
ext R25,R2,0,8
b BFDW_end

BFDW_Jump1:
ext R25,R2,8,8
b BFDW_end

BFDW_Jump2:
ext R25,R2,16,8
b BFDW_end

BFDW_Jump3:
ext R25,R2,24,8

BFDW_end:
end;
result := R2;
end;
Attachments
error messages from compiler
error messages from compiler
Skjermbildeiii.JPG (89.31 KiB) Viewed 1732 times

tormod
Posts: 57
Joined: 29 Nov 2004 16:31

Re: mikropascal addressing through table in assembly

#2 Post by tormod » 13 Apr 2019 20:04

By rewriting the routine I came up with the following:

function __SkrBitExtractByteFromDWord(Value : dword; Position : byte) : byte;

begin
asm
ori R3,R0,R0
beq R3,R26,BFDW_Jump0
NOP
addiu R3,R3,1
beq R3,R26,BFDW_Jump1
NOP
addiu R3,R3,1
beq R3,R26,BFDW_Jump2
NOP
ext R25,R2,24,8
b BFDW_end
NOP

BFDW_Jump0:
ext R25,R2,0,8
b BFDW_end
NOP

BFDW_Jump1:
ext R25,R2,8,8
b BFDW_end
NOP

BFDW_Jump2:
ext R25,R2,16,8

BFDW_end:
end;
result := R25;
end;

Can be used to extract any of 4 byte in a dword numbered 0-3. Still interested in addressing by table if anyone have some ideas . Compiler always returns values in R2, so it transferres R25 to R2 - unecessary but the compiler does not accept a non-result from a function.

BFDW_end:
;SkrBit.mpas,169 :: result := R25;
; Result start address is: 8 (R2)
MOVZ R2, R25, R0
;SkrBit.mpas,170 :: end;
; Result end address is: 8 (R2)
L_end___SkrBitExtractByteFromDWord:
JR RA
NOP
; end of ___SkrBitExtractByteFromDWord

Post Reply

Return to “mikroPascal PRO for PIC32 General”