assembler language assembler language macro boot camp
play

Assembler Language Assembler Language Macro "Boot Camp" - PowerPoint PPT Presentation

Assembler Language Assembler Language Macro "Boot Camp" Macro "Boot Camp" Part 2 Part 2 SHARE in Austin SHARE in Austin March 1 - 6, 2009 March 1 - 6, 2009 Session 8159 Session 8159 1 Who am I? Who am I? Michael


  1. Assembler Language Assembler Language Macro "Boot Camp" Macro "Boot Camp" Part 2 Part 2 SHARE in Austin SHARE in Austin March 1 - 6, 2009 March 1 - 6, 2009 Session 8159 Session 8159 1

  2. Who am I? Who am I? Michael Stack, K Cats Consulting Instructor in Computer Science at Northern Illinois University from 1982 - 2007, including assembler language, data structures (in assembler), and applied systems programming 2

  3. Available Materials Available Materials Materials described in these two sessions, as well as the Assembler Boot Camp, can be found at http://www.kcats.org/share 3

  4. Yesterday's Agenda (Brief Review) Yesterday's Agenda (Brief Review) Our First Macro Instruction The Second Version of Our ADD Macro The Macro Programming Language 4

  5. Today's Agenda Today's Agenda Variable Symbols We Can Change A Bit More on Variable Symbols Finally, the Add Macro Instruction Wrap Up 5

  6. Variable Symbols Variable Symbols We Can Change We Can Change (So that's that's why they're called why they're called (So Set Symbols) Symbols) Set 6

  7. Set Symbols Set Symbols Now that we have AIf and AGo to control the path of code generation, it will be very useful to have a way to keep assembly-time data Assembler variables which can hold this data are called set symbols, of which there are three data types A rithmetic B inary (logical) C haracter 7

  8. Set Symbol Scope Set Symbol Scope As with high level languages, set symbol variables have the scope characteristic The value assigned to a local set symbol is known only within one macro expansion, and each expansion of that - or any other - macro has its own copy of that local variable The value assigned to a global set symbol is known throughout the assembly 8

  9. Set Symbol Declaration Set Symbol Declaration Modern assemblers do not require that local Set Symbols be declared before use (older assemblers do, though) But it's a good idea to declare (and globals require it), as it's a great place to document the purpose of the variable Declaration describes the variable as L ocal or G lobal A rithmetic, B inary, or C haracter 9

  10. Set Symbol Declaration Set Symbol Declaration To declare a local set symbol of type x (where x is A, B, or C): seq_sym Lclx var_sym 1 ,var_sym 2 ,... where seq_sym may be a sequence symbol and each var_sym n is a variable symbol To declare a global set symbol of type x: seq_sym Gblx var_sym 1 ,var_sym 2 ,... Although more than one set symbol can be declared in one statement, limiting to one leaves room for a descriptive comment 10

  11. Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment The SetA instruction is used to assign a value to an arithmetic set symbol (from now on called a SetA symbol) var_sym SetA arithmetic_expression var_sym is a variable symbol and arithmetic_expression (as described earlier) is evaluated as a signed, 32-bit number The default (initial) value of a SetA symbol is zero 11

  12. Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example Here is some sample code: LclA &S Counter LclA &Con Assigned "constant" &S SetA 3 Initial value &S SetA &S+1 Increment by 1 &Con SetA 2*(1-&S) Set &Con to -6 And here's a real oddity: when &Con (whose value now is -6) is used in a model statement, its absolute value is used: DC F'&Con' Generates 00000006 (Don't ask) 12

  13. Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example Here is some more sample code, this one to generate all of the register equates: Macro EQURegs GblA &EQURegs Recall if already done LclA &Reg Counter (initially 0) AIf (&EQURegs NE 0).Done &EQURegs SetA 1 Don't generate again .Loop ANOP R&Reg EQU &Reg &Reg SetA &Reg+1 Increment reg number AIf (&Reg LE 15).Loop .Done MEnd 13

  14. Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example Here is the output (assembler source) from EQURegs (first time only!) EQURegs +R0 EQU 0 +R1 EQU 1 +R2 EQU 2 +R3 EQU 3 +R4 EQU 4 ... +R12 EQU 12 +R13 EQU 13 +R14 EQU 14 +R15 EQU 15 14

  15. Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example Here is a slightly different version of the same macro (loop test at top): Macro EQURegs GblA &EQURegs Recall if already done LclA &Reg Counter (initially 0) AIf (&EQURegs NE 0).Done &EQURegs SetA 1 Don't generate again .Loop AIf (&Reg GT 15).Done R&Reg EQU &Reg &Reg SetA &Reg+1 Increment reg number AGo .Loop .Done MEnd 15

  16. Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Assignment The SetB instruction is used to assign a value to a binary set symbol (from now on called a SetB symbol) var_sym SetB binary_value var_sym is a variable symbol and binary_value (described in the next slide) is evaluated as a 0 or 1 The default (initial) value of a SetB symbol is zero 16

  17. Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Assignment A full description of the binary_value operand of SetB is beyond the scope of these sessions; simplified, it can be one of A binary digit (0 or 1) A binary value enclosed in parentheses An arithmetic value enclosed in parentheses If the value is 0, the assembler assigns a value of 0 to the symbol in the name field; if the value is not 0, the assembler assigns a value of 1 A logical expression enclosed in parentheses 17

  18. Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Examples Assignment Examples Each &X starts with initial &A , &B , & &C &A SetA 4 &B SetB 1 (Note no parentheses) &C SetC 'XYZ' (This is a preview of SetC!) * &X SetB (&B) &X = ? &X SetB (NOT &B) &X = ? &X SetB (&A LE 15) &X = ? &X SetB ('&C' EQ 'XYZ') &X = ? &X SetB ((NOT &B) AND (&A LT 15)) &X = ? &X SetB ((&A GT 0) AND (&A LT 15)) &X = ? &X SetB (&B OR ('&C' EQ 'YES')) &X = ? &X SetB (&B AND NOT (&A GT 5)) &X = ? 18

  19. Character Set Symbol Character Set Symbol Assignment Assignment The SetC instruction is used to assign a value to a character set symbol (from now on called a SetC symbol) var_sym SetC 'character_string' note quotes! character_string is a sequence of characters and variable symbols (followed by ' . ' for concatenation) interpreted as characters The initial value of a SetC symbol is the null string 19

  20. Character Set Symbol Character Set Symbol Assignment Examples Assignment Examples Here is a SetC example: &A SetA 4 &B SetB 1 &C SetC 'XYZ' * &X SetC 'A&A.B&B.C&C.' &X = ? &X evaluates to the string A4B1CXYZ Note that the arithmetic and binary values have been converted to character values (See Concatenation in the next section) 20

  21. Substrings of SetC Symbols Substrings of SetC Symbols Definition Definition SetC operands can also be substrings by placing two arithmetic expressions, separated by commas and enclosed in parentheses, immediately following the character expression The first arithmetic expression identifies the first character of the substring The second arithmetic expression gives the length of the substring 21

  22. Substrings of SetC Symbols Substrings of SetC Symbols Examples Examples 'ABCDEF'(3,2) evaluates to 'CD' If &VAR evaluates to 2 and &STR evaluates to 'ABCD' then '&STR.%'(2,&VAR*2) evaluates to 'BCD%' 'AB'.'CD'.'EFG'(1,2).'H' evaluates to 'ABCDEFH' (For . see concatenation in the next section) 22

  23. A Bit More on A Bit More on Variable Symbols Variable Symbols Then we can really really go to work! go to work! Then we can Meeting in Progress 23

  24. Concatenation Concatenation Concatenation can sometimes be without ambiguity &this&that (variable.variable) this&that (ordinary.variable) Others are a problem &thisthat (variable.ordinary intended) We use the concatenation operator ' . ' to avoid the ambiguity &this.that 24

  25. Symbolic Parameter Sublists Symbolic Parameter Sublists A single macro operand can be a list of elements, called a sublist, with one or more items enclosed in parentheses and separated by commas (X,2,Y) An individual sublist item can be referred to by a subscripted symbolic parameter, so if &ABC has the value (W,15) &ABC(1) has the value W &ABC(2) has the value 15 But &ABC.(1) has the value (W,15)(1) 25

  26. Keyword Symbolic Parameters Keyword Symbolic Parameters Macro prototype statements may have keyword operands as well as positional These are coded on the prototype as &Keyword=[default] The default value is optional The advantages of keyword parameters are They can have a default value They can be coded in any order when invoked But positionals look more like operands 26

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend