1 / 15

Week 12

Week 12. Assembly Language. Assembly language programs manipulates the resources of the CPU Registers, ALU and memory Keeping track of these resources and their various states of usage is a keep aspect of this type of programming

yuri
Download Presentation

Week 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 12

  2. Assembly Language • Assembly language programs manipulates the resources of the CPU • Registers, ALU and memory • Keeping track of these resources and their various states of usage is a keep aspect of this type of programming • Assembler accepts the source code and produces the resulting machine code • This is an unambiguous operation, with a one-to-one relationship

  3. Assembly Code • Each line of machine code can have up to four fields label: opcode/assdir operand(s) comment • Label field is optional • Represents the symbolic address of the instruction (or data) that follows it • Used by the assembler in generating machine code for jump instructions or locations of data. • Opcode/assdir field contains • Opcode of instruction or assembler directive • Opcodes (with operands) are translated in machine code • Assembler directives are commands (directives) to direct the assembler to do something

  4. Assembly Code • Operand(s) • Information required by instruction • Instruction specific • Includes immediate values registers, memory addresses, indirect address, symbolic constants, expressions • Comments • Ignored by assembler, but important means of documentation

  5. Org 0x0048 MOV A,#0 JNB 0x93,Act CLR 0x55 Act: MOV R1,0x45 JMP Fin CLR 0x56 Fin: CLR C Example shows example program with assembler directives, label and instructions The org directive does not produce any code, but tells the assembler that what follows it, starts at address 0x48. This is clearly very important in absolute jump and call instructions Assembly Code

  6. Assemblers • Types of assemblers • Macro assemblers • Two-pass asemblers • Native assemmblers • Cross assemblers • Assembler outputs • Hex output • Widely used format. ASCII file. Used in programming actual devices • Lst output • Contains source and assembled code and symbol tables

  7. Assembler Directives • Command interpreted by assembler that causes the assember to perform specific action • Several such commands • Control placement of code • Define symbolic values • Reserve and initialise storage • Does not result in the generation of machine code • With the exception of a few assembler directives, they have no effect on code memory • DB, DD, DS

  8. Common directives • ORG • Used for address control • Example ORG 0x0040 • Used to alter the internal counter used by the assembler to keep track of instruction addresses • END • Indicates end of program

  9. Common directives • DB • Used to initialise code memory Values: DB ‘1’,’gooo’,’0’,LOW(Values) • Causes 4 bytes to be initialised • Comma separated list of expressions follows DB • Other forms include DD and DW

  10. Common directives • EQU • Allows the creation of symbolic constants for the program • Makes programs more readable • Symbols can be used anywhere in program • Addresses, constants, operands or within expressions

  11. Common directives • Absolute segment directives • CSEG,DSEG,XSEG,ISEG and DSEG • Allows the absolute locating of data or code at fixed locations • Relocatable segment directives • SEGMENT • Allows specification of relocatable program section

  12. Lookup table example • Note 8051 does not have efficient means of doing this! MOV A, #0x0A CALL GETVAL …… GETVAL: ; subroutine to index table ; with contents of A PUSH ACC MOV A, #0Ah MOV DPTR, #TABLE MOVC A, @A+DPTR POP ACC RET TABLE: DB '0','1','2','3','4','5','6','7' DB '8','9','A','B','C','D','E','F'

  13. Absolute Assembler • Machine code is located absoluted following assembly • Fine for small dedicated tasks • Restrictive • Code located in one file • Cannot not support creation of code library • Does not support loading of code to different memory space • This is what we’ve worked with this semester

  14. Relocatable Assember • Source file does not have to be complete • Does not have to contain location information or ORG statements • Where missing locations occur (e.g. jump address), a separate table of missing info is appended to the resulting object file. • Do not create hex file, since all information is not there • Separate program called a linker combines object file(s) and library code to produce an executable • Linker also given info about locations for code and data • For systems using OS, there is also the added operation of loading executable

  15. Register banking • 4 register banks exist • Each has 8 registers named R0-R7 • Active bank is determined by two bits (I.e. 4 possibilities) in the PSW • Used for ISRs to allow fast task switching

More Related