Lecture 16 Pico Blaze Instruction Set Assembler Directives
Lecture 16 Pico. Blaze Instruction Set & Assembler Directives ECE 448 – FPGA and ASIC Design with VHDL
Required reading • P. Chu, FPGA Prototyping by VHDL Examples Chapter 15 Pico. Blaze Assembly Code Develop Recommended reading • K. Chapman, Pico. Blaze for Spartan-6, Virtex-6, and 7 -Series (KCPSM 6) ECE 448 – FPGA and ASIC Design with VHDL 2
Pico. Blaze-6 Programming Model Bank A Bank B FFC FFD FFE FFF ECE 448 – FPGA and ASIC Design with VHDL 3
Syntax and Terminology Syntax Example s. X s 7 KK 0 x. AB PORT(KK) PORT(2) Definition Value at register 7 Constant AB (in hex) Input value from port 2 PORT((s. X)) PORT((sa)) Input value from the port specified RAM(KK) RAM(4) by register a Value from RAM location 4
Addressing modes Immediate mode SUB s 7, 0 x 07 ADDC s 2, 0 x 08 s 7 <= s 7 – 0 x 07 s 2 <= s 2 + 0 x 08 + C Direct mode ADD sa, sf IN s 5, 0 x 2 a Indirect mode STORE s 3, (sa) IN s 9, (s 2) sa <= sa + sf s 5 <= PORT(0 x 2 a) RAM((sa)) <= s 3 s 9 <= PORT((s 2))
Pico. Blaze Development Environments Xilinx KCPSM 3/ 6 Open. PIC IDE Platform support Windows XP, Windows 7 and 8 Assembler Command-line in DOS window Graphical Instruction Syntax Open. PIC Instruction Set Simulator KCPSM 3/ 6 Facilities provided for VHDL simulation Simulator Breakpoints N/A Yes Register Viewer N/A Yes Memory Viewer N/A Yes Graphical/ Interactive
KCPSM 6 Assembler Files KCPSM 6. EXE ECE 448 – FPGA and ASIC Design with VHDL
Directives of Assembly Language Function Locating Code Aliasing Register Names Declaring Constants KCPSM 3/ 6 Directive ADDRESS 3 FF NAMEREG s 5, myregname CONSTANT myconstant, 80 Name using the same base Naming the program ROM filename as the assembler source file Equating symbolic name for an I/O port ID N/A Open. PIC Directive ORG 0 x 3 FF myregname EQU s 5 myconstant EQU 0 x 80 Specify the VHDL template file in the project settings under processor tab and compiler options sw_port EQU 0 x 01 ; 8 -bit switches sw_in EQU sf IN sw_in, sw_port ; read switch input data EQU s 0 ; reg for tmp data led_port EQU 0 x 05 OUT data, led_port
Differences between Mnemonics of Instructions KCPSM 3/ 6 Mnemonic Open. PIC Mnemonic RETURN C RETURN NC RETURN Z RETURN NZ RETURNI ENABLE RETURNI DISABLE RETI DISABLE ENABLE INTERRUPT EINT DISABLE INTERRUPT DINT
Differences between Mnemonics of Instructions ADDCY s. X, s. Y ADDC s. X, s. Y SUBCY s. X, s. Y SUBC s. X, s. Y INPUT s. X, (s. Y) INPUT s. X, kk IN s. X, kk OUTPUT s. X, (s. Y) OUT s. X, (s. Y) COMPARE s. X, s. Y COMP s. X, s. Y STORE s. X, (s. Y) FETCH s. X, (s. Y)
Differences between Programs
Basic Data Movement Instructions
Data Movement Instructions CZ IMM, DIR LOAD s. X, s. Y s. X <= s. Y LOAD s. X, KK s. X <= KK -
Logic Instructions & Bit Manipulation
Logic instructions 1. AND s. X, s. Y s. X <= s. X and s. Y AND s. X, KK s. X <= s. X and KK 2. OR OR s. X, s. Y s. X <= s. X or s. Y OR s. X, KK s. X <= s. X or KK 3. XOR s. X, s. Y s. X <= s. X xor s. Y XOR s. X, KK s. X <= s. X xor KK CZ IMM, DIR 0
Questions Perform the following operations in the assembly language of Pico. Blaze 1. Set the most significant bit of the register s 0 to 1 1. Clear two middle bits of the register s 1 1. Toggle the least significant bit of the register s 2
Answers 1. Set the most significant bit of the register s 0 to 1 BIT 7 EQU 0 x 80 OR s 0, BIT 7 2. Clear two middle bits of the register s 1 BITS 43 C EQU 0 x. E 7 AND s 1, BITS 43 C 3. Toggle the least significant bit of the register s 2 BIT 0 EQU 0 x 01 XOR s 2, BIT 0
Arithmetic Instructions & Multiple-Byte Manipulation
Arithmetic Instructions (1) CZ Addition IMM, DIR ADD s. X, s. Y s. X <= s. X + s. Y ADD s. X, KK s. X <= s. X + KK ADDC s. X, s. Y s. X <= s. X + s. Y + CARRY ADDC s. X, KK s. X <= s. X + KK + CARRY
Questions Perform the following operation in the assembly language of Pico. Blaze Add two 3 -byte numbers X=(x 2, x 1, x 0) and Y=(y 2, y 1, y 0), stored originally in registers (s 2, s 1, s 0) and (s 5, s 4, s 3), accordingly.
Answer x 0 x 1 x 2 y 0 y 1 y 2 EQU EQU EQU s 0 s 1 s 2 s 3 s 4 s 5 ADD x 0, y 0 ADDC x 1, y 1 ADDC x 2, y 2
Arithmetic Instructions (2) CZ Subtraction SUB s. X, s. Y s. X <= s. X – s. Y SUB s. X, KK s. X <= s. X – KK SUBC s. X, s. Y s. X <= s. X – s. Y – CARRY SUBC s. X, KK s. X <= s. X – KK – CARRY IMM, DIR
Questions Perform the following operation in the assembly language of Pico. Blaze Perform the subtraction X=X-Y, where X=(x 2, x 1, x 0) and Y=(y 2, y 1, y 0), and these variables are originally stored in registers (s 2, s 1, s 0) and (s 5, s 4, s 3), accordingly.
Answer x 0 x 1 x 2 y 0 y 1 y 2 EQU EQU EQU s 0 s 1 s 2 s 3 s 4 s 5 SUB x 0, y 0 SUBC x 1, y 1 SUBC x 2, y 2
Shifts & Rotations
Edit instructions - Shifts *All shift instructions affect Zero and Carry flags
Edit instructions - Rotations *All rotate instructions affect Zero and Carry flags
Questions Perform the following operation in the assembly language of Pico. Blaze Perform the left shift (C, X) <= X << 1, where X = (x 2, x 1, x 0) is stored in registers (s 2, s 1, s 0), and the most significant bit of X is shifted into the carry flag.
Answer x 0 x 1 x 2 EQU s 0 EQU s 1 EQU s 2 SL 0 SLA x 0 x 1 x 2
Test, Compare, and Program Flow Instructions
Test and Compare Instructions CZ TEST IMM, DIR TEST s. X, s. Y C = odd parity of s. X and s. Y => none TEST s. X, KK the result s. X and KK => none COMPARE COMP s. X, s. Y s. X – s. Y => none COMP s. X, KK s. X – KK => none IMM, DIR
Program Flow Control Instructions (1) JUMP AAA PC <= AAA JUMP C, AAA if C=1 then PC <= AAA else PC <= PC + 1 JUMP NC, AAA if C=0 then PC <= AAA else PC <= PC + 1 JUMP Z, AAA if Z=1 then PC <= AAA else PC <= PC + 1 JUMP NZ, AAA if Z=0 then PC <= AAA else PC <= PC + 1
If-else statement C if (s 0 == s 1) { ………. } else { ………. . } Assembly language
If-else statement C Assembly language if (s 0 == s 1) { ………. } else { ………. . } COMP s 0, s 1 JUMP NZ, else_branch ………. . JUMP if_done else_branch: ………. . if_done:
Switch statement C switch (s 0) { case value_1: ………. break; case value_2: ………. break; case value_3: ………. break; default: ………. break; } Assembly language
Switch statement C switch (s 0) { case value_1: ………. break; case value_2: ………. break; case value_3: ………. break; default: ………. break; } Assembly language COMP s 0, value_1 JUMP NZ, case_2 ………. JUMP case_done case_2: COMP s 0, value_2 JUMP NZ, case_3 ………. JUMP case_done case_3: COMP s 0, value_3 JUMP NZ, default ………. JUMP case_done default: ………. case_done:
For loop C for(i=MAX, i>=0, i--) { …………… } Assembly language
For loop C for(i=MAX; i>0; i--) { …………… } for(i=MAX; i>=0; i--) { …………… } Assembly language LOAD s 0, MAX for_loop: ………. SUB s 0, 1 JUMP NZ, for_loop LOAD s 0, MAX for_loop: ………. SUB s 0, 1 JUMP NC, for_loop
Subroutines
Subroutine-Related Instructions CALL AAA TOS <= TOS+1; STACK[TOS] <= PC; PC <= AAA CALL C | Z , AAA if C | Z =1 then TOS <= TOS+1; STACK[TOS] <= PC; PC <= AAA else PC <= PC + 1 CALL NC | NZ , AAA if C | Z =0 then TOS <= TOS+1; STACK[TOS] <= PC; PC <= AAA else PC <= PC + 1
Subroutine-Related Instructions RET PC <= STACK[TOS] + 1; TOS <= TOS - 1 RET C|Z if C | Z =1 then PC <= STACK[TOS] + 1; TOS <= TOS - 1 else PC <= PC + 1 RET NC | NZ if C | Z =0 then PC <= STACK[TOS] + 1; TOS <= TOS - 1 else PC <= PC + 1
Subroutine Call Flow
Instructions Involving Data Memory
Data Movement Instructions Involving Data Memory CZ DIR, IND STORE s. X, KK RAM(KK) <= s. X - STORE s. X, s. Y RAM((s. Y)) <= s. X DIR, IND FETCH s. X, KK s. X <= RAM(KK) FETCH s. X, (s. Y) s. X <= RAM((s. Y) -
Example 1: Clear Data RAM of the size of 64 bytes ; ============================= ; routine: clr_data_mem ; function: clear data ram ; temp register: data, s 2 ; ============================= RAM_SIZE EQU 0 x 40 ; size of RAM = 64 clr_data_mem: load s 2, RAM_SIZE ; unitize loop index to 64 load s 0, 0 x 00 clr_mem_loop: sub s 2, 0 x 01 ; dec loop index store s 0, (s 2) jump nz, clr_mem_loop ret ; repeat until s 2=0
Input/Output Instructions
Input/Output Instructions DIR, IND IN IN s. X, KK s. X <= PORT(KK) CZ - IN s. X, (s. Y) s. X <= PORT((s. Y)) DIR, IND OUT s. X, KK PORT(KK) <= s. X OUT s. X, (s. Y) PORT((s. Y)) <= s. X -
Example 2: Clear External RAM of the size of 64 bytes ; ============================= ; routine: clr_ext_mem ; function: clear data ram ; temp register: data, s 2 ; ============================= RAM_SIZE EQU 0 x 40 ; size of RAM = 64 clr_ext_mem: load s 2, RAM_SIZE ; unitize loop index to 64 load s 0, 0 x 00 clr_mem_loop: sub s 2, 0 x 01 ; dec loop index out s 0, (s 2) jump nz, clr_mem_loop return ; repeat until s 2=0
- Slides: 48