EMT 248 Introduction to Assembly Language Programming Instruction
EMT 248: Introduction to Assembly Language Programming (Instruction Set cont. ) Semester II 2009/10 School of Microelectronic Engineering Universiti Malaysia Perlis
Assembly Language Format Label • Start : • • Delimiter Colon Space Comma Semicolon Opcode LXI Operand SP, 3 FF 0 H Comment ; Initialize stack pointer Placement After label Between an opcode and an operan Between two operand Before beginning of a comment
Assembler Directive ORG (Origin) END EQU DFB (define byte) DFW (define Word) DFS (define Storage) Example ORG 2000 H Description The next block of instructions should store in memory starting at 2000 H END End of assembly PORTA: EQU 80 H The value of term PORTA is equal to 80 H DATA: DFB 10 H, 30 H Initializes an area byte by byte DATA: DFW 2020 H Initializes an area two byte at time DATA: DFS 10 Reserves a specified number of memory
Flowchart : Program Assembly & Execution Start Write /Edit Source Program Assemble Source File Yes Expected Result? No Troubleshot/Debug Yes Errors? Go Back to Edit Errors No Generate Hex / List File Download Hex File into Target System & Execute Program End
Example (Sample Source Code) NUM 1: NUM 2: CPU “ 8085. TBL” ORG 2000 H EQU 55 H EQU 78 H LXI SP, 3 FF 0 H ; Initialize Stack pointer MVI A, NUM 1 ; load first number MOV B, A ; save it to B register MVI A, NUM 2 ; load second number ADD B ; add register A & B STA RESULT ; store to 2050 H RST 1 ORG 2050 H RESULT: DFS 1 ; reserve 1 byte location in END ; memory (Note: write your source code using any text editor)
Manual assembly *Please Refer to 8085 Assembly Code Summary page 782 8085 Assembly Codes INSTRUCT LOGICAL OP-CODE BYTE T-STATE MOV B, A (B) (A) 47 1 4 LXI SP, data 16 (SP) (byte 3) (SP) (byte 2) 31 3 10 FLAGS _ S Z P CY AC
Manual assembly Address (Hex) 2000 2003 2005 2006 2008 2009 200 C Program Code LXI SP, 3 FF 0 H MVI A, NUM 1 MOV B, A MVI A, NUM 2 ADD B STA RESULT RST 1 Machine Code (Hex)
Exercise PORTA: LOOP: DELAY: LOOP 1: CPU “ 8085. TBL” ORG 2000 H EQU 80 H LXI SP, 3 FF 0 H XRA A CMA OUT PORTA CALL DELAY JMP LOOP MVI B, 255 DCR B JNZ LOOP 1 RET END ; Initialize Stack pointer
Manual assembly Address (Hex) Program Code 2000 LXI SP, 3 FF 0 H 2003 XRA A 2004 CMA 2005 OUT PORTA 2007 CALL DELAY 200 A JMP LOOP 200 D MVI B, 255 200 F DCR B 2010 JNZ LOOP 1 2013 RET Machine Code (Hex)
Assembler The Assembler is a program that translates source code or mnemonics into the binary code (machine code). In addition to translating mnemonics, the Assembler performs various functions, such as error checking and memory allocations.
Source File (Example. ASM) Assembler (Translator) HEX File Listing File (Example. HEX) (Example. LST)
Example of Listing File 00000 CPU "8085. TBL" 02000 00000055 00000078 ORG 2000 H EQU = = NUM 1: NUM 2: 02000 31 F 03 F 02003 3 E 55 02005 47 02006 3 E 78 02008 80 02009 325020 0200 C CF 02050 RESULT: 00000055 NUM 1 00000078 NUM 2 00002050 RESULT LXI SP, 3 FF 0 H MVI A, NUM 1 MOV B, A MVI A, NUM 2 ADD B STA RESULT RST 1 ORG 2050 H DFS END 55 H 78 H ; Initialize Stack pointer ; load first number ; save it to B register ; load second number ; add register A & B ; store to 2050 H 1 ; reserve 1 byte location in ; memory
Example of Hex File : 020000 FC : 0 D 20000031 F 03 F 3 E 55473 E 7880325020 CFF 2 : 00000001 FF : 0 D 20000031 F 03 F 3 E 55473 E 7880325020 CFF 2 Byte Count Record Type Address Data Byte (Program Code) Checksum
• Byte Count The number of data bytes in the record • Address of the first data byte in the record. Address in End of File record is 0000 • Record Type The record type for a data record is 00. The record type for an End of File record is 01 • Data Byte Data byte in HEX ASCII. Two character per byte. • Checksum Two’s complement byte of binary sum of preceding byte in record; Including byte count, address and data byte
Testing & Debugging • Download Hex File into Target System & Execute Program 8085 Development System is communicated with PC through serial port (RS 232). RS 232 PC 8085 Development Board
Exercise Give 3 Example & 1 exercise
- Slides: 16