Home
Appendix 4 Alecsis assembler
Contents
1. Those are additional instructions supporting some of most frequently used functions This makes a program more effective especially in the case of mathematical functions which are used often in modelling of analogue circuits mnemonic syntax operation supported types putchar putchar l op d0 putchar op fputc l opl op2 dO fputc opl op2 1 1 sdo fgetc op 1 strcpy strcpy l opl op2 dO0 strcpy opl op2 l strcmp l opl op2 dO strcmp opl op2 1 strlen i malloc 1 calloc 1 free free op attr attr L indx offset returns the address of user defined 1 attributes for signals with the position indx and offset offset slen l indx offset returns the length of the signal vector 1 with the position indx and offset offset d0_ fabs op ia d0 exp op d0 log op log10 d0 log10 op d0 pow op sqrt d0 sqrt op sin d0 sin op d0 cos tan d op dO tan slen cos tan tan d op asin dO asin op acos dO acos op atan dO atan op Q e o o 5 Fo sinh sinh op cosh cosh op tanh zd0 tanh op floor d0 floor op ceil z You can use coprocessor instructions by honouring standard conventions 2 2 atan2 atan2 d opl op2 d0 atan2 opl op2 y Q o Qu Qs Qs Os Or Qs Or Qs Os OG Qs r Qs Qs Qs Qs Qu y Q e m o ceil op Appendix 4 Alecsis assembler 203 A4 3 Conve
2. inside an asm region or even outside it but within the original function or a process The instruction itself can have label using the syntax explained in Chapter 3 The names of functions in the code are created using the mechanism known as name mangling Chapter 4 You can see how this name is created if you compile the file containing the definition of the function using the option S and read its name from the assembler file For example function 200 Alecsis 2 3 User s manual int foo int int double class Point can be called using instruction asm jsr dn foo iiPPd5Point e where dn labels the beginning of memory occupied by the function arguments The name of the function is prolonged with extensions that explain which formal parameters are declared for function foo This enables function overloading When using temporary registers dn you can cross over limit of 64 bytes Actually all registers with the index larger than sizeof double will be transferred to the local memory allocated as much as needed This especially refers to passing down the arguments during a function call A4 2 Assembler instructions Most of instructions for virtual processor have more than one version The current implementation of virtual processor supports the following types b byte 1 long d double Some instructions do not have all of these types or have one as default The type is appended as the extension of t
3. all interim results that were on locations d8 n In our example function main has two local variables of type int 2x4 bytes and uses two positions of a register d to pass arguments 2x4 bytes totalling 16 since we used long variant of instruction link this number is divided by sizeof long Function test allocates space only for its local variable k The result of the function is returned through the accumulator from dO to d7 After that the program jumps to label LO where it frees local space and exits from the function The results larger than 8 bytes return to address O address of formal parameters using instruction movm The previous example can be realized using combined AleC assembler syntax int z 204 Alecsis 2 3 User s manual main int x y asm movq l d8 x movq l d12 y jsr d8 test ii movq l z d0 test int i int j int k asm add l i j o movq l k d0 return k This example leaves instructions link and inlk to the compiler this is a standard procedure when using asm command This applies in both cases to command return too In pointer arithmetic you should be careful when dealing with address registers Register a0 is reserved for vector indexing Therefore the code int i j a 10 b b ali jl compiles to add l i j addr l a dO movq l b a0 which means that the instruction addr puts the address amp a sizeof long i j int
4. 1 define atof 27 define atoi 28 The missing indices are used for internal system functions which only compiler can call By appending this library you can write movq 1 d8 Hello world n jin d8 printf which has the same effect as AleC command printf Hello world n You can find all other details linked with using assembler by compiling the source code using option S and by direct comparison of source and compiled code Notice that you cannot use directly the code obtained in this manner Assembler instructions need to be inside asm command for compiler to accept them The closing example will be a recursive function for calculating the factorial of 170 in double precision include alec h double factor double i if i lt 1 return 1 0 return i factor i 1 int main double i 170 printf tfactor g g n i factor i 206 Alecsis 2 3 User s manual Alecsis assembler code optimization off function factor d factor d link b 50 8 le d S f0 1 movq 1 d0 dO jz L1 movq d dO 1 jp LO L1 sub d S f0 1 movq d vO d0 jsr v0 factor d mul d f0 30 movq d 30 dO jp LO LO unlk b0 rts function main main link b bO 28 movq d vO 170 movq 1 v8 tfactor g g n movq d v12 vO movq d v20 SVO jsr v20 factor d movq d v20 d0 jfn v8 O0 LO unlk Sb0 rts
5. Appendix 4 Alecsis assembler Virtual processor is one of the main parts of Alecsis simulation engine It emulates the behaviour of a real hardware processor by executing commands successively according to type The set of legal instructions for the virtual processor comes with adaptations and changes from the set for MC68020 Motorola microprocessor Text in AleC can be translated into the assembly language assembler code if you use option S file with the extension as in the program call Besides you can write assembler code in the text using command asm see chapter 2 It is not likely that the user may need assembler commands for modelling and simulation However it may be necessary to understand assembler if the problems arise when installing Alecsis on different computers When using assembler you can encounter some memory problems problems with honouring various conventions etc thus you need to be careful when using it The use of assembler is tolerated only for writing of very difficult functions whose time of execution is crucial for the program Compiler sometimes copies interim results into temporary registers to protect them from deleting This can be more than necessary sometimes but compiler uses the safer method Since Alecsis does not have a multipassage optimizer besides the peephole optimizer which does not deal with the code as a whole but only with 2 3 neighbouring instructions there is always room for a shorte
6. and arguments beginning from the address op1 jnz label jump to labelif do 0 jp label jump to label jsr opl op2 jump to function with address op2 and arguments beginning from address o TRY o o ar FR o pb le o o H ajaja o Hh Q C Fh 5 H 5 Q 5 ct O O o o ok lolol h oo P PRIN THIN E SPP el a Q Q op1 jz label jump to label if dO 0 le t opl op2 lea opl op2 Tink t 4b0 size lsl t opl op2 lsla t opl op2 IE t opl Gp b i mod t opl op2 d0 opl op2 moda moda t opl op2 move t opl op2 00 opl op2 movem opl op2 copying of content of op2 to op1 number of copied bytes is determined by the instruction mset movq t opl op2 mset mset op control of instruction movm dO opl op2 mula t opl op2 neg neg t op neq neg t opl opp d0 opl op2 b 1 d rts rts exit from a procedure sub sub t opl op2 dO0 opl op2 suba t opl op2 d0 opl op2 Bid B bq l opl opz Pp u U u m M w link lsl lsla H ct n unlk unlk 50 return of the local memory stack during the exit from a procedure d0_ opl op2 202 Alecsis 2 3 User s manual xora t opl op2 d0 opl op2 b 1 A4 2 2 Instructions of Alecsis virtual coprocessor In the previous section basic instruction set of virtual processor is given Beside those instruction virtual processor has something you can call coprocessor
7. declaration san general purpose address registers min 64 bytes ssn local static memory id identifier id name with external linking San content of memory pointed to by the address register dereferencing Sbn register pointing to resource vector sen memory of the n th element if it has parameters enn memory of the value of the signal at the position n in processes in the current time instant The last two operands can appear in processes only since they refer to object that can be declared only in modules All elements are indexed by the order of declaration with the index 0 being the first element Operand points to the pointer to memory of action parameters if the component has them The last operand points to the memory containing the value of the signal with the index n formal parameters are indexed as 0 1 2 while the local ones as 1 2 3 To get the real address you need to multiply the index and the length of every signal in bytes Beside these operands all expressions of AleC can be found in instructions including constants and variables For example int A gs Zij asm movq l i j The previous command copies the content of variable j into variable i You should avoid complex expressions since they can use some registers in the way that creates a conflict with the current instruction Operand of instructions for conditional or unconditional branching can be name of a label which can be
8. he instruction mnemonics add 1 move d The type gives information about the number of bytes used by the instruction sometime the meaning of the instruction too The exception is the pair mset movm where you can copy an unlimited number of bytes mset 64 movm sl s2 In this example the first 64 bytes pointed to by the external symbol s2 are copied to external symbol s1 A4 2 1 Instructions of Alecsis virtual processor mnemonic syntax operation supported adda t T op2 d addr addr t opl op2 a0 op2 Indexing b l d operation has a type to render multiplication of the index by the type opi SD L sddg addg t opl op2 opl amp op2_ 1 TIU IT pend bat opi opa sao epi amp opi at banda banda t opl op2 d0 opl amp opp b l1 bnand d H o o o H Biene op amp do op amp Oop2 ae ae bnor t mes bnot op o rn oojo bor _ bor t SBI op2 bora t opl E zao opl op oe Q eo ll O Ha o H Appendix 4 Alecsis assembler 201 bxnor t opl d0 opl op2 op2 conb conb t op conversion of op from type byte into typet op p p b 1 d b 1 d Bije Tij g into type t into type t dev t opl op2 deva t opl op2 eq eq t opl op2 d0_ opl op2 ge ge t opl op d0 opl gt opp b 1 d gt t opl op2 1 incr 1 opl findx jump to the intrinsic function with the index findx
9. ntions on passing parameters to functions The mechanism of function call and the return from functions used by the virtual processor will be explained on the following example int Zz main int X yj z test x y test int i int j int k k 2ic Jj return k This code would be compiled as follows comments in the code are added available register after the accumulator main link l b0 4 movq l d8 vO movq l d12 v4 jsr d8 _ movq l z d0 L0 unlk b0 rts test ii link b b0 4 add l f 0 f4 movq l vO dO movq l d0 vO jp LO LO unlk b0 rts test ii call of func test allocating 16 bytes of local space placing variable i v0 into the first d0 to d7 placing variable j into the next one the name is completed result returned via d0 freeing local space end of function allocating 4 bytes of local space adding of formal variables i and j storing the result into the variable k return of the result compulsory jump to the output label free the space allocated using link to freeing local space end of function The arguments are passed in the following manner they are lined up continually into the register dn starting from the first free position the lowest position is d8 since the accumulator occupies the first 8 bytes Instruction link allocates space for all local variables and
10. o the address register a O0 The following instruction copies the content of that address in the register into variable b Parentheses can dereference only address registers To dereference a pointer you need to transfer it into an address register int i j 10 J L2 LS This code is equivalent to the following code addr l j 2 movq l a4 i mova l a0 a4 Note that pointer occupy 4 bytes so the first free place was a4 after a O0 had been used Instruction 1ea does the referencing int i j j amp i lea dO i Appendix 4 Alecsis assembler 205 movq l j dO Compiler implements referencing in two steps but it is the standard procedure for the optimizer to merge two steps into one lea j i Built in functions are called using command j n and they cannot be mixed with ordinary functions since their address cannot be obtained The first operand is the address of the first argument while the second one is an integer constant used for indexing Indexes of all intrinsic functions that are not instructions are in the file asm h in directory alecsis include The following is the content of the file define printf 0 define fprintf T define sprintf 2 define fflush 3 define _fopen 4 define fclose 5 define feof 6 define _fseek 7 define ftell 8 define fread 9 define fwrite 10 define rewind 11 define exit 12 define system T3 define warning 16 define drand 17 define get info 2
11. r and more efficient code written in assembler Optimizing can however lead you into dangerous waters which require the knowledge and understanding of the work of virtual processor Notice that Alecsis always creates the shortest code from the given text syntax directed compilation Mentioned optimizations refer to rearrangement of some expression in order to eliminate extraneous calculations 198 Appendix 4 Alecsis assembler 199 A4 1 Operands in assembler instructions The cycle of the virtual processor divides into two phases fetching of operands and execution of instructions Some conventions regulate what can be an assembler operand Primary basic operands refer to a part of memory called resource in Alecsis That is an internal table containing the base addresses off all regions the potential operands can come from Operation fetch comes down to two additions one when indexing resource tables and the other for addition of the address obtained in that way and the operand offset The position in the table is set using mnemonics pointing the type of the source while offset is given by a number Virtual processor supports the following resource mnemonics mnemonic always goes after the character Sdn general purpose registers min 64 bytes vn local memory allocated using instruction 1ink fn formal parameter or action parameter inside a process zmn object passed to a function or a process if it fits the
Download Pdf Manuals
Related Search
Related Contents
Handbuch als PDF downloaden - delight Istruzioni di montaggio e manutenzione Cooper Bussmann BRICK 6125TD User's Manual Copyright © All rights reserved.
Failed to retrieve file