Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 18 PicoBlaze Instruction Set & Assembler Directives

Similar presentations


Presentation on theme: "Lecture 18 PicoBlaze Instruction Set & Assembler Directives"— Presentation transcript:

1 Lecture 18 PicoBlaze Instruction Set & Assembler Directives
ECE 448 – FPGA and ASIC Design with VHDL

2 Required reading Recommended reading
P. Chu, FPGA Prototyping by VHDL Examples Chapter 15 PicoBlaze Assembly Code Development Recommended reading K. Chapman, PicoBlaze for Spartan-6, Virtex-6, 7-Series, Zynq and UltraScale Devices (KCPSM6)) ECE 448 – FPGA and ASIC Design with VHDL

3 PicoBlaze-6 Programming Model
Bank B Bank A FFC FFD FFE FFF ECE 448 – FPGA and ASIC Design with VHDL

4 Syntax and Terminology
Syntax Example Definition sX KK PORT(KK) PORT((sX)) RAM(KK) s7 0xAB PORT(2) PORT((sa)) RAM(4) Value at register 7 Constant AB (in hex) Input value from port 2 Input value from the port specified by register a Value from RAM location 4

5 Addressing modes Immediate mode SUB s7, 0x07 s7 <= s7 – 0x07
s2 <= s2 + 0x08 + C Immediate mode SUB s7, 0x07 ADDC s2, 0x08 Direct mode ADD sa, sf IN s5, 0x2a sa <= sa + sf s5 <= PORT(0x2a) Indirect mode STORE s3, sa IN s9, s2 RAM((sa)) <= s3 s9 <= PORT((s2))

6 PicoBlaze Development Environments
Xilinx KCPSM3/6 FIDEx IDE Platform support Windows Assembler Command-line in DOS window Graphical Instruction Syntax KCPSM3/6 Instruction Set Simulator Facilities provided for VHDL simulation Graphical/ Interactive Simulator Breakpoints N/A Yes Register Viewer Memory Viewer

7 ECE 448 – FPGA and ASIC Design with VHDL
KCPSM6 Assembler Files KCPSM6.EXE ECE 448 – FPGA and ASIC Design with VHDL

8 Differences between Mnemonics of Instructions
KCPSM3/ 6 Mnemonic FIDEx IDE Mnemonic RETURN RET RETURN C RET C RETURN NC RET NC RETURN Z RET Z RETURN NZ RET NZ RETURNI ENABLE RETI ENABLE RETURNI DISABLE RETI DISABLE ENABLE INTERRUPT EINT DISABLE INTERRUPT DINT

9 Differences between Mnemonics of Instructions
ADDCY sX, sY ADDC sX, sY SUBCY sX, sY SUBC sX, sY INPUT sX, (sY) IN sX, sY INPUT sX, kk IN sX, kk OUTPUT sX, (sY) OUT sX, sY OUTPUT sX, kk OUT sX, kk COMPARE sX, sY COMP sX, sY

10 Assembler Directives (FIDEx IDE)
#EQU yourConstant, 0x3A ; defines your constant #EQU yourRegName, s ; renames a PicoBlaze register #ORG ADDR, n ; sets the memory address of the following instruction to n #DEFINE case0 ; chooses among multiple program variants #IFDEF case0 ….. #ELSEIF case1 | case2 ..... #ENDIF

11 Basic Data Movement Instructions

12 Data Movement Instructions
C Z - - LOAD LOAD sX, sY sX <= sY LOAD sX, KK sX <= KK IMM, DIR

13 Logic Instructions & Bit Manipulation

14 Logic instructions C Z IMM, DIR IMM, DIR IMM, DIR AND AND sX, sY
sX <= sX and sY AND sX, KK sX <= sX and KK 2. OR OR sX, sY sX <= sX or sY OR sX, KK sX <= sX or KK 3. XOR XOR sX, sY sX <= sX xor sY XOR sX, KK sX <= sX xor KK IMM, DIR IMM, DIR IMM, DIR

15 Perform the following operations in the assembly language of PicoBlaze
Questions Perform the following operations in the assembly language of PicoBlaze Set the most significant bit of the register s0 to 1 Clear two middle bits of the register s1 Toggle the least significant bit of the register s2

16 Answers Set the most significant bit of the register s0 to 1
#EQU BIT7, 0x80 OR s0, BIT7 Clear two middle bits of the register s1 #EQU BITS43C, 0xE7 AND s1, BITS43C Toggle the least significant bit of the register s2 #EQU BIT0, 0x01 XOR s2, BIT0

17 Arithmetic Instructions & Multiple-Byte Manipulation

18 Arithmetic Instructions (1)
C Z Addition ADD sX, sY sX <= sX + sY ADD sX, KK sX <= sX + KK ADDC sX, sY sX <= sX + sY + CARRY ADDC sX, KK sX <= sX + KK + CARRY IMM, DIR

19 Perform the following operation in the assembly language of PicoBlaze
Questions Perform the following operation in the assembly language of PicoBlaze Add two 3-byte numbers X=(x2, x1, x0) and Y=(y2, y1, y0), stored originally in registers (s2, s1, s0) and (s5, s4, s3), accordingly.

20 Answer #EQU x0, s0 #EQU x1, s1 #EQU x2, s2 #EQU y0, s3 #EQU y1, s4
ADD x0, y0 ADDC x1, y1 ADDC x2, y2

21 Arithmetic Instructions (2)
C Z Subtraction SUB sX, sY sX <= sX – sY SUB sX, KK sX <= sX – KK SUBC sX, sY sX <= sX – sY – CARRY SUBC sX, KK sX <= sX – KK – CARRY IMM, DIR

22 Perform the following operation in the assembly language of PicoBlaze
Questions Perform the following operation in the assembly language of PicoBlaze Perform the subtraction X=X-Y, where X=(x2, x1, x0) and Y=(y2, y1, y0), and these variables are originally stored in registers (s2, s1, s0) and (s5, s4, s3), accordingly.

23 Answer #EQU x0, s0 #EQU x1, s1 #EQU x2, s2 #EQU y0, s3 #EQU y1, s4
SUB x0, y0 SUBC x1, y1 SUBC x2, y2

24 Shifts & Rotations

25 Edit instructions - Shifts
*All shift instructions affect Zero and Carry flags

26 Edit instructions - Rotations
*All rotate instructions affect Zero and Carry flags

27 Perform the following operation in the assembly language of PicoBlaze
Questions Perform the following operation in the assembly language of PicoBlaze Perform the left shift (C, X) <= X << 1, where X = (x2, x1, x0) is stored in registers (s2, s1, s0), and the most significant bit of X is shifted into the carry flag.

28 Answer #EQU x0, s0 #EQU x1, s1 #EQU x2, s2 SL0 x0 SLA x1 SLA x2

29 and Program Flow Instructions
Test, Compare, and Program Flow Instructions

30 Test and Compare Instructions
C Z TEST TEST sX, sY sX and sY => none TEST sX, KK sX and KK => none COMPARE COMP sX, sY sX – sY => none COMP sX, KK sX – KK => none IMM, DIR C = odd parity of the result IMM, DIR

31 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

32 If-else statement C Assembly language if (s0 == s1) { ………. } else {
………..

33 If-else statement C Assembly language if (s0 == s1) { COMP s0, s1 ……….
} else { ……….. COMP s0, s1 JUMP NZ, else_branch ……….. JUMP if_done else_branch: if_done:

34 Switch statement C Assembly language switch (s0) { case value_1: ……….
break; case value_2: case value_3: default: }

35 Switch statement C Assembly language switch (s0) { case value_1: ……….
COMP s0, value_1 JUMP NZ, case_2 ………. JUMP case_done case_2: COMP s0, value_2 JUMP NZ, case_3 case_3: COMP s0, value_3 JUMP NZ, default default: case_done: switch (s0) { case value_1: ………. break; case value_2: case value_3: default: }

36 For loop C Assembly language for(i=MAX, i>=0, i--) { …………… }

37 For loop C Assembly language for(i=MAX; i>0; i--) { …………… }
LOAD s0, MAX for_loop: ………. SUB s0, 1 JUMP NZ, for_loop for(i=MAX; i>=0; i--) { …………… } LOAD s0, MAX for_loop: ………. SUB s0, 1 JUMP NC, for_loop

38 Subroutines & Interrupts

39 Subroutine-Related Instructions
CALL AAA TOS <= TOS+1; STACK[TOS] <= PC; PC <= AAA CALL C | Z , AAA if C | Z =1 then else PC <= PC + 1 CALL NC | NZ , AAA if C | Z =0 then

40 Subroutine-Related Instructions
RET PC <= STACK[TOS] + 1; TOS <= TOS - 1 RET C | Z if C | Z =1 then else PC <= PC + 1 RET NC | NZ if C | Z =0 then

41 Subroutine Call Flow

42 ECE 448 – FPGA and ASIC Design with VHDL
Interrupt Flow ECE 448 – FPGA and ASIC Design with VHDL

43 Interrupt Related Instructions
RETI ENABLE PC <= STACK[TOS] ; TOS <= TOS – 1; I <= 1; C<= PRESERVED C; Z<= PRESERVED Z RETI DISABLE I <= 0; C<= PRESERVED C; Z<= PRESERVED Z EINT I <=1; DINT I <=0;

44 Instructions Involving
Data Memory

45 Data Movement Instructions
Involving Data Memory C Z - - STORE STORE sX, KK RAM(KK) <= sX STORE sX, sY RAM((sY)) <= sX DIR, IND - - FETCH FETCH sX, KK sX <= RAM(KK) FETCH sX, sY sX <= RAM((sY) DIR, IND

46 Example 1: Clear Data RAM of the size of 64 bytes
;========================================================= ; routine: clr_data_mem ; function: clear data ram ; temp register: data, s2 RAM_SIZE EQU 0x ; size of RAM = 64 clr_data_mem: load s2, RAM_SIZE ; unitize loop index to 64 load s0, 0x00 clr_mem_loop: sub s2, 0x ;dec loop index store s0, s2 jump nz, clr_mem_loop ;repeat until s2=0 ret

47 Input/Output Instructions

48 Input/Output Instructions
C Z - - DIR, IND IN IN sX, KK sX <= PORT(KK) IN sX, sY sX <= PORT((sY)) OUT OUT sX, KK PORT(KK) <= sX OUT sX, sY PORT((sY)) <= sX - - DIR, IND

49 Example 2: Clear External RAM of the size of 64 bytes
;========================================================= ; routine: clr_ext_mem ; function: clear data ram ; temp register: data, s2 RAM_SIZE EQU 0x ; size of RAM = 64 clr_ext_mem: load s2, RAM_SIZE ; unitize loop index to 64 load s0, 0x00 clr_mem_loop: sub s2, 0x ;dec loop index out s0, s2 jump nz, clr_mem_loop ;repeat until s2=0 return


Download ppt "Lecture 18 PicoBlaze Instruction Set & Assembler Directives"

Similar presentations


Ads by Google