Beruflich Dokumente
Kultur Dokumente
A B C D E F I J L M N O R S T W X
1 add beq call div eret flushd initd jmp ldb/ ldbio mov nextpc or rdctl sll trap wrctl xor
2 addi bge callr divu flushda initda jmpi ldbu/ ldbuio movhi nop orhi rdrps slli wrprs xorhi
3 and bgeu cmpeq flushi initi ldh/ ldhio movi nor ori ret sra xori
4 andhi bgt cmpeqi flushp ldhu/ ldhuio movia rol srai
5 andi bgtu cmpge ldw/ ldwio movui roli srl
6 ble cmpgei mul ror srli
7 bleu cmpgeu muli stb/ stbio
8 blt cmpgeui mulxss sth/ sthio
9 bltu cmpgt mulxsu stw/ stwio
10 bne cmpgti mulxuu sub
11 br cmpgtu subi
12 break cmpgtui sync
13 bret cmple
14 cmplei
15 cmpleu
16 cmpleui
17 cmplt
18 cmplti
19 cmpltu
20 cmpltui
21 cmpne
22 cmpnei
23 custom
62
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
o Nội dung các ghi chú được sử dụng trong bảng liệt kê các lệnh dưới đây
Ghi chú Ý nghĩa
X Y X is written with Y
The program counter (PC) is written with address X; the instruction at X
PC X
is the next instruction to execute
PC The address of the assembly instruction in question
rA, rB, rC One of the 32-bit general-purpose registers
IMMn An n-bit immediate value, embedded in the instruction word
IMMED An immediate value
Xn The nth bit of X, where n = 0 is the LSB
Xn..m Consecutive bits n through m of X
0xNNMM Hexadecimal notation
Bitwise concatenation
X:Y
For example, (0x12 : 0x34) = 0x1234
The value of X after being sign-extended into a full register-
𝛿(𝑥)
sized signed integer
X >> n The value X after being right-shifted n bit positions
X << n The value X after being left-shifted n bit positions
X&Y Bitwise logical AND
X|Y Bitwise logical OR
X^Y Bitwise logical XOR
~X Bitwise logical NOT (one’s complement)
Mem8[X] The byte located in data memory at byte-address X
Mem16[X] The halfword located in data memory at byte-address X
Mem32[X] The word located in data memory at byte-address X
Label An address label specified in the assembly file
(signed) rX The value of rX treated as a signed number
(unsigned) rX The value of rX, treated as an unsigned number
62
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
Assembler Syntax: add rC, rA, rB Assembler Syntax: addi rB, rA, IMM16
Example: add r6, r7, r8 Example: addi r6, r7, -100
Exceptions: None Exceptions: None
Instruction Type: R Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
C = Register index of operand rC IMM16 = 16-bit signed immediate value
and (A3) andhi (A4)
bitwise logical and bitwise logical and immediate into high halfword
Description: Calculates the bitwise logical AND of rA and Description: Calculates the bitwise logical AND of rA and
rB and stores the result in rC (IMM16 : 0x0000) and stores the result in rB.
Operation: rC ← rA & rB Operation: rB ← rA & (IMM16 : 0x0000)
Assembler Syntax: and rC, rA, rB Assembler Syntax: andhi rB, rA, IMM16
Example: and r6, r7, r8 Example: andhi r6, r7, 100
Exceptions: None Exceptions: None
Instruction Type: R Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
C = Register index of operand rC IMM16 = 16-bit unsigned immediate value
andi (A5) beq (A6)
bitwise logical and immediate branch if equal
Description: Calculates the bitwise logical AND of rA and Description: If rA == rB, then beq transfers program
(0x0000 : IMM16) and stores the result in rB. control to the instruction at label. In the instruction
Operation: rB ← rA & (0x0000 : IMM16) encoding, the offset given by IMM16 is treated as a signed
Assembler Syntax: andi rB, rA, IMM16 number of bytes relative to the instruction immediately
Example: andi r6, r7, 100 following beq. The two least-significant bits of IMM16 are
Exceptions: None always zero, because instruction addresses must be word-
Instruction Type: I aligned.
Instruction Fields: A = Register index of operand rA Operation: if (rA == rB)
B = Register index of operand rB then PC ← PC + 4 + σ (IMM16)
IMM16 = 16-bit unsigned immediate value else PC ← PC + 4
Assembler Syntax: beq rA, rB, label
Example: beq r6, r7, label
Exceptions: Misaligned destination address
Instruction Type: I
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit signed immediate value
bge (A7) bgeu (A8)
branch if greater than or equal signed branch if greater than or equal unsigned
Description: If (signed)rA>=(signed)rB, then bge transfers Description: If (unsigned)rA>=(unsigned)rB, then bgeu
program control to the instruction at label. In the transfers program control to the instruction at label. In the
instruction encoding, the offset given by IMM16 is treated instruction encoding, the offset given by IMM16 is treated
as a signed number of bytes relative to the instruction as a signed number of bytes relative to the instruction
immediately following bge. The two least-significant bits immediately following bgeu. The two least-significant bits
of IMM16 are always zero, because instruction addresses of IMM16 are always zero, because instruction addresses
must be word-aligned. must be word-aligned.
Operation: if ((signed)rA >= (signed) rB) Operation: if ((unsigned)rA >= (unsigned)rB)
then PC← PC+4+ σ (IMM16) then PC←PC+4 + σ (IMM16)
else PC ← PC+4 else PC ←PC+4
Assembler Syntax: bge rA, rB, label Assembler Syntax: bgeurA,rB,label
Example: bge r6, r7, top_of_loop Example: bgeur6,r7,top_of_loop
Exceptions: Misaligned destination address Exceptions: Misaligned destination address
Instruction Type: I Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
63
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
IMM16 = 16-bit signed immediate value IMM16 = 16-bit signed immediate value
bgt (A9) bgtu (A10)
branch if greater than signed branch if greater than unsigned
Description: If (signed)rA>(signed)rB, then bgt transfers Description: If (unsigned)rA>(unsigned)rB, then bgtu
program control to the instruction at label. transfers program control to the instruction at label.
Pseudo-instruction: bgt is implemented with the blt Pseudo-instruction: bgtu is implemented with the bltu
instruction by swapping the register operands instruction by swapping the register operands.
Operation: if ((signed)rA>(signed)rB) Operation: if ((unsigned)rA>(unsigned)rB)
then PC ← label then PC ← label
else PC ← PC+4 else PC ← PC+4
Assembler Syntax: bgt rA, rB, label Assembler Syntax: bgtu rA, rB, label
Example: bgt r6, r7, top_of_loop Example: bgtu r6, r7, top_of_loop
ble (A11) bleu (A12)
branch if less than or equal signed branch if less than or equal to unsigned
Description: If (signed)rA<=(signed)rB, then ble transfers Description: If (unsigned)rA<=(unsigned)rB, then bleu
program control to the instruction at label. transfers program counter to the instruction at label.
Pseudo-instruction: ble is implemented with the bge Pseudo-instruction: bleu is implemented with the bgeu
instruction by swapping the register operands. instruction by swapping the register operands.
Operation: if ((signed)rA<=(signed)rB) Operation: if ((unsigned)rA<=(unsigned) rB)
then PC ← label then PC ← label
else PC ← PC+4 else PC ← PC+4
Assembler Syntax: ble rA, rB, label Assembler Syntax: bleu rA, rB, label
Example: ble r6, r7, top_of_loop Example: bleu r6, r7, top_of_loop
blt (A13) bltu (A14)
branch if less than signed branch if less than unsigned
Description: If (signed)rA<(signed)rB, then blt transfers Description: If (unsigned)rA<(unsigned)rB, then bltu
program control to the instruction at label. In the transfers program control to the instruction at label. In the
instruction encoding, the offset given by IMM16 is treated instruction encoding, the offset given by IMM16 is treated
as a signed number of bytes relative to the instruction as a signed number of bytes relative to the instruction
immediately following blt. The two least-significant bits of immediately following bltu. The two least-significant bits
IMM16 are always zero, because instruction addresses of IMM16 are always zero, because instruction addresses
must be word-aligned. must be word-aligned.
Operation: if ((signed)rA<(signed)rB) Operation: if ((unsigned)rA<(unsigned)rB)
then PC ←PC+4+ σ (IMM16) then PC ← PC+4+ σ (IMM16)
else PC ←PC+4 else PC ← PC+4
Assembler Syntax: blt rA, rB, label Assembler Syntax: bltu rA, rB, label
Example: blt r6, r7, top_of_loop Example: bltu r6, r7, top_of_loop
Exceptions: Misaligned destination address Exceptions: Misaligned destination address
Instruction Type: I Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
IMM16 = 16-bit signed immediate value IMM16 = 16-bit signed immediate value
bne (A15) br (A16)
branch if not equal unconditional branch
Description: If rA != rB, then bne transfers program Description: Transfers program control to the instruction at
control to the instruction at label. In the instruction label. In the instruction encoding, the offset given by
encoding, the offset given by IMM16 is treated as a signed IMM16 is treated as a signed number of bytes relative to
number of bytes relative to the instruction immediately the instruction immediately following br. The two least-
following bne. The two least-significant bits of IMM16 are significant bits of IMM16 are always zero, because
always zero, because instruction addresses must be word- instruction addresses must be word-aligned.
aligned. Operation: PC ← PC+4+ σ (IMM16)
Operation: if (rA != rB) Assembler Syntax: br label
then PC ← PC+4+ σ (IMM16) Example: br top_of_loop
else PC ← PC+4 Exceptions: Misaligned destination address
Assembler Syntax: bne rA, rB, label Instruction Type: I
Example: bne r6, r7,top_of_loop Instruction Fields:
64
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
65
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
implement the C logical negation operator “!”. Usage: cmpeqi performs the == operation of the C
Operation: if (rA == rB) programming language
then rC ←1 Operation: if (rA σ (IMM16))
else rC ←0 then rB ←1
Assembler Syntax: cmpeq rC, rA, rB else rB ←0
Example: cmpeq r6, r7, r8 Assembler Syntax: cmpeqi rB, rA, IMM16
Exceptions: None Example: cmpeqi r6, r7, 100
Instruction Type: R Exceptions: None
Instruction Fields: A = Register index of operand rA Instruction Type: I
B = Register index of operand rB Instruction Fields: A = Register index of operand rA
C = Register index of operand rC B = Register index of operand rB
IMM16 = 16-bit signed immediate value
cmpge (B7) cmpgei (B8)
compare greater than or equal signed compare greater than or equal signed immediate
Description: If rA >= rB, then stores 1 to rC; otherwise Description: Sign-extends the 16-bit immediate value
stores 0 to rC. IMM16 to 32 bits and compares it to the value of rA. If
Usage: cmpge performs the signed >= operation of the C rA >= σ (IMM16), then cmpgei stores 1 to rB; otherwise
programming language. stores 0 to rB.
Operation: if ((signed) rA >= (signed) rB) Usage: cmpgei performs the signed >= operation of the C
then rC ←1 programming language.
else rC ←0 Operation: if ((signed) rA >= (signed) σ (IMM16))
Assembler Syntax: cmpge rC, rA, rB then rB←1
Example: cmpge r6, r7, r8 else rB ←0
Exceptions: None Assembler Syntax: cmpgei rB, rA, IMM16
Instruction Type: I Example: cmpgei r6, r7, 100
Instruction Fields: A = Register index of operand rA Exceptions: None
B = Register index of operand rB Instruction Type: R
C = Register index of operand rC Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit signed immediate value
cmpgeu (B9) cmpgeui (B10)
compare greater than or equal unsigned compare greater than or equal unsigned immediate
Description: If rA >= rB, then stores 1 to rC; otherwise Description: Zero-extends the 16-bit immediate value
stores 0 to rC. IMM16 to 32 bits and compares it to the value of rA. If
Usage: cmpgeu performs the unsigned >= operation of the rA >= (0x0000 : IMM16), then cmpgeui stores 1 to rB;
C programming language. otherwise stores 0 to rB.
Operation: if ((unsigned) rA >= (unsigned) rB) Usage: cmpgeui performs the unsigned >= operation of the
then rC ←1 C programming language.
else rC ←0 Operation:
Assembler Syntax: cmpgeu rC, rA, rB if ((unsigned) rA >= (unsigned) (0x0000 : IMM16))
Example: cmpgeu r6, r7, r8 then rB ←1
Exceptions: None else rB ←0
Instruction Type: R Assembler Syntax: cmpgeui rB, rA, IMM16
Instruction Fields: A = Register index of operand rA Example: cmpgeui r6, r7, 100
B = Register index of operand rB Exceptions: None
C = Register index of operand rC Instruction Type: I
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit unsigned immediate value
cmpgt (B11) cmpgti (B12)
compare greater than signed compare greater than signed immediate
Description: If rA > rB, then stores 1 to rC; otherwise Description: Sign-extends the immediate value IMMED to
stores 0 to rC. 32 bits and compares it to the value of rA. If rA >
Usage: cmpgt performs the signed > operation of the C σ (IMMED), then cmpgti stores 1 to rB; otherwise stores 0
programming language. to rB.
Operation: if ((signed) rA > (signed) rB) Usage: cmpgti performs the signed > operation of the C
66
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
67
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
cmpgeu instruction by swapping its rA and rB operands. Assembler Syntax: cmpleui rB, rA, IMMED
Example: cmpleui r6, r7, 100
Pseudo-instruction: cmpleui is implemented using a
cmpltui instruction with an IMM16 immediate value of
IMMED + 1.
cmplt (C3) cmplti (C4)
compare less than signed compare less than signed immediate
Description: If rA < rB, then stores 1 to rC; otherwise Description: Sign-extends the 16-bit immediate value
stores 0 to rC. IMM16 to 32 bits and compares it to the value of rA. If
Usage: cmplt performs the signed < operation of the C rA < σ (IMM16), then cmplti stores 1 to rB; otherwise
programming language. stores 0 to rB.
Operation: if ((signed) rA < (signed) rB) Usage: cmplti performs the signed < operation of the C
then rC ←1 programming language.
else rC ←0 Operation: if ((signed) rA < (signed) σ (IMM16))
Assembler Syntax: cmplt rC, rA, rB then rB ←1
Example: cmplt r6, r7, r8 else rB ←0
Exceptions: None Assembler Syntax: cmplti rB, rA, IMM16
Instruction Type: R Example: cmplti r6, r7, 100
Instruction Fields: A = Register index of operand rA Exceptions: None
B = Register index of operand rB Instruction Type: I
C = Register index of operand rC Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit signed immediate value
cmpltu (C5) cmpltui (C6)
compare less than unsigned compare less than unsigned immediate
Description: If rA < rB, then stores 1 to rC; otherwise Description: Zero-extends the 16-bit immediate value
stores 0 to rC. IMM16 to 32 bits and compares it to the value of rA. If
Usage: cmpltu performs the unsigned < operation of the C rA < (0x0000 : IMM16), then cmpltui stores 1 to rB;
programming language. otherwise stores 0 to rB.
Operation: if ((unsigned) rA < (unsigned) rB) Usage: cmpltui performs the unsigned < operation of the C
then rC ←1 programming language.
else rC ←0 Operation:
Assembler Syntax: cmpltu rC, rA, rB if ((unsigned) rA < (unsigned) (0x0000 : IMM16))
Example: cmpltu r6, r7, r8 then rB ←1
Exceptions: None else rB ←0
Instruction Type: R Assembler Syntax: cmpltui rB, rA, IMM16
Instruction Fields: A = Register index of operand rA Example: cmpltui r6, r7, 100
B = Register index of operand rB Exceptions: None
C = Register index of operand rC Instruction Type: I
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit unsigned immediate value
cmpne (C7) cmpnei (C8)
compare not equal compare not equal immediate
Description: If rA != rB, then stores 1 to rC; otherwise Description: Sign-extends the 16-bit immediate value
stores 0 to rC. IMM16 to 32 bits and compares it to the value of rA. If
Usage: cmpne performs the != operation of the C rA != σ (IMM16), then cmpnei stores 1 to rB; otherwise
programming language. stores 0 to rB.
Operation: if (rA != rB) Usage: cmpnei performs the != operation of the C
then rC ←1 programming language.
else rC ←0 Operation: if (rA != σ (IMM16))
Assembler Syntax: cmpne rC, rA, rB then rB←1
Example: cmpne r6, r7, r8 else rB ←0
Exceptions: None Assembler Syntax: cmpnei rB, rA, IMM16
Instruction Type: R Example: cmpnei r6, r7, 100
Instruction Fields: A = Register index of operand rA Exceptions: None
68
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
69
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
70
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
mapped data cache, initd clears the data cache line without mapped data cache, initda clears the data cache line without
checking for (or writing) a dirty data cache line that is checking for (or writing) a dirty data cache line that is
mapped to the specified address back to memory. Unlike mapped to the specified address back to memory. Unlike
initda, initd clears the cache line regardless of whether the initd, initda clears the cache line only when the addressed
addressed data is currently cached. This process comprises data is currently cached. This process comprises the
the following steps: following steps:
■ Compute the effective address specified by the sum of rA ■ Compute the effective address specified by the sum of rA
and the signed 16-bit immediate value. and the signed 16-bit immediate value.
■ Identify the data cache line associated with the computed ■ Identify the data cache line associated with the computed
effective address. Each data cache effective address effective address. Each data cache effective address
comprises a tag field and a line field. When identifying the comprises a tag field and a line field. When identifying the
line, initd ignores the tag field and only uses the line field line, initda uses both the tag field and the line field.
to select the data cache line to clear. ■ Compare the cache line tag with the effective address to
■ Skip comparing the cache line tag with the effective determine if the addressed data is currently cached. If the
address to determine if the addressed data is currently tag fields do not match, the effective address is not
cached. Because initd ignores the cache line tag, initd currently cached, so the instruction does nothing.
flushes the cache line regardless of whether the specified ■ Skip checking if the data cache line is dirty. Because
data location is currently cached. initd skips the dirty cache line check, data that has been
■ Skip checking if the data cache line is dirty. Because modified by the processor, but not yet written to memory is
initd skips the dirty cache line check, data that has been lost.
modified by the processor, but not yet written to memory is ■ Clear the valid bit for the line.
lost. If the NiosII processor core does not have a data cache, the
■ Clear the valid bit for the line. initda instruction performs no operation.
If the NiosII processor core does not have a data cache, the Usage: Use initda to skip writing dirty lines back to
initd instruction performs no operation. memory and to flush the cache line only if the addressed
Usage: Use initd after processor reset and before accessing memory location is currently in the cache.
data memory to initialize the processor’s data cache. Use Operation: Initializes the data cache line currently caching
initd with caution because it does not write back dirty data. address rA+ σ (IMM16)
Operation: Initializes the data cache line associated with Assembler Syntax: initda IMM16(rA)
address rA+ σ (IMM16). Example: initda -100(r6)
Assembler Syntax: initd IMM16(rA) Exceptions: Supervisor-only data address
Example: initd 0(r6) Fast TLB miss (data)
Exceptions: Supervisor-only instruction Double TLB miss (data)
Instruction Type: I MPU region violation (data)
Instruction Fields: A = Register index of operand rA Unimplemented instruction
IMM16 = 16-bit signed immediate value Instruction Type: I
Instruction Fields: A = Register index of operand rA
IMM16 = 16-bit signed immediate value
initi (D3) jmp (D4)
initialize instruction cache line computed jump
Description: Ignoring the tag, initi identifies the instruction Description: Transfers execution to the address contained
cache line associated with the byte address in ra, and initi in register rA.
invalidates that line. If the NiosII processor core does not Usage: It is illegal to jump to the address contained in
have an instruction cache, the initi instruction performs no register r31. To return from subroutines called by call or
operation. callr, use ret instead of jmp.
Usage: This instruction is used to initialize the processor’s Operation: PC ← rA
instruction cache. Immediately after processor reset, use Assembler Syntax: jmp rA
initi to invalidate each line of the instruction cache. Example: jmp r12
Operation: Initializes the instruction cache line associated Exceptions: Misaligned destination address
with address rA. Instruction Type: R
Assembler Syntax: initi rA Instruction Fields: A = Register index of operand rA
Example: initi r6
Exceptions: Supervisor-only instruction
Instruction Type: R
Instruction Fields: A = Register index of operand rA
jmpi (D5) ldb / ldbio (D6)
jump immediate load byte from memory or I/O peripheral
71
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
Description: Transfers execution to the instruction at Description: Computes the effective byte address specified
address (PC31…28 : IMM26 × 4). by the sum of rA and the instruction's signed 16-bit
Usage: jmpi is a low-overhead local jump. jmpi can immediate value. Loads register rB with the desired
transfer execution anywhere within the 256-MB range memory byte, sign extending the 8-bit value to 32 bits. In
determined by PC31..28. The NiosII GNU linker does not NiosII processor cores with a data cache, this instruction
automatically handle cases in which the address is out of may retrieve the desired data from the cache instead of
this range. from memory.
Operation: PC ← (PC31..28 : IMM26 × 4) Usage: Use the ldbio instruction for peripheral I/O. In
Assembler Syntax: jmpi label processors with a data cache, ldbio bypasses the cache and
Example: jmpi write_char is guaranteed to generate an Avalon-MM data transfer. In
Exceptions: None processors without a data cache, ldbio acts like ldb.
Instruction Type: J Operation: rB ← σ (Mem8[rA + σ (IMM16)])
Instruction Fields: Assembler Syntax: ldb rB, byte_offset(rA)
IMM26 = 26-bit unsigned immediate value ldbio rB, byte_offset(rA)
Example: ldb r6, 100(r5)
Exceptions: Supervisor-only data address
Misaligned data address
TLB permission violation (read)
Fast TLB miss (data)
Double TLB miss (data)
MPU region violation (data)
Instruction Type: I
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit signed immediate value
ldbu / ldbuio (D7) ldh / ldhio (D8)
load unsigned byte from memory or I/O peripheral load halfword from memory or I/O peripheral
Description: Computes the effective byte address specified Description: Computes the effective byte address specified
by the sum of rA and the instruction's signed 16-bit by the sum of rA and the instruction's signed 16-bit
immediate value. Loads register rB with the desired immediate value. Loads register rB with the memory
memory byte, zero extending the 8-bit value to 32 bits. halfword located at the effective byte address, sign
Usage: In processors with a data cache, this instruction extending the 16-bit value to 32 bits. The effective byte
may retrieve the desired data from the cache instead of address must be halfword aligned. If the byte address is not
from memory. Use the ldbuio instruction for peripheral I/O. a multiple of 2, the operation is undefined.
In processors with a data cache, ldbuio bypasses the cache Usage: In processors with a data cache, this instruction
and is guaranteed to generate an Avalon-MM data transfer. may retrieve the desired data from the cache instead of
In processors without a data cache, ldbuio acts like ldbu. from memory. Use the ldhio instruction for peripheral I/O.
Operation: rB ← 0x000000 : Mem8[rA + σ (IMM16)] In processors with a data cache, ldhio bypasses the cache
Assembler Syntax: ldbu rB, byte_offset(rA) and is guaranteed to generate an Avalon-MM data transfer.
ldbuio rB, byte_offset(rA) In processors without a data cache, ldhio acts like ldh.
Example: ldbu r6, 100(r5) Operation: rB ← σ (Mem16[rA + σ (IMM16)])
Exceptions: Supervisor-only data address Assembler Syntax: ldh rB, byte_offset(rA)
Misaligned data address ldhio rB, byte_offset(rA)
TLB permission violation (read) Example: ldh r6, 100(r5)
Fast TLB miss (data) Exceptions: Supervisor-only data address
Double TLB miss (data) Misaligned data address
MPU region violation (data) TLB permission violation (read)
Instruction Type: I Fast TLB miss (data)
Instruction Fields: A = Register index of operand rA Double TLB miss (data)
B = Register index of operand rB MPU region violation (data)
IMM16 = 16-bit signed immediate value Instruction Type: I
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
IMM16 = 16-bit signed immediate value
ldhu / ldhuio (D9) ldw / ldwio (D10)
load unsigned halfword from memory or I/O peripheral load 32 bit word from memory or I/O peripheral
Description: Computes the effective byte address specified Description: Computes the effective byte address specified
72
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
by the sum of rA and the instruction's signed 16-bit by the sum of rA and the instruction's signed 16-bit
immediate value. Loads register rB with the memory immediate value. Loads register rB with the memory word
halfword located at the effective byte address, zero located at the effective byte address. The effective byte
extending the 16-bit value to 32 bits. The effective byte address must be word aligned. If the byte address is not a
address must be halfword aligned. If the byte address is not multiple of 4, the operation is undefined.
a multiple of 2, the operation is undefined. Usage: In processors with a data cache, this instruction
Usage: In processors with a data cache, this instruction may retrieve the desired data from the cache instead of
may retrieve the desired data from the cache instead of from memory. Use the ldwio instruction for peripheral I/O.
from memory. Use the ldhuio instruction for peripheral I/O. In processors with a data cache, ldwio bypasses the cache
In processors with a data cache, ldhuio bypasses the cache and memory. Use the ldwio instruction for peripheral I/O.
and is guaranteed to generate an Avalon-MM data transfer. In processors with a data cache, ldwio bypasses the cache
In processors without a data cache, ldhuio acts like ldhu. and is guaranteed to generate an Avalon-MM data transfer.
Operation: rB ←0x0000 : Mem16[rA + σ (IMM16)] In processors without a data cache, ldwio acts like ldw.
Assembler Syntax: ldhurB, byte_offset(rA) Operation: rB ← Mem32[rA + σ (IMM14)]
ldhuio rB, byte_offset(rA) Assembler Syntax: ldw rB, byte_offset(rA)
Example: ldhu r6, 100(r5) ldwio rB, byte_offset(rA)
Exceptions: Supervisor-only data address Example: ldw r6, 100(r5)
Exceptions: Supervisor-only data address Exceptions: Supervisor-only data address
Misaligned data address Misaligned data address
TLB permission violation (read) TLB permission violation (read)
Fast TLB miss (data) Fast TLB miss (data)
Double TLB miss (data) Double TLB miss (data)
MPU region violation (data) MPU region violation (data)
Instruction Type: I Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
IMM16 = 16-bit signed immediate value IMM16 = 16-bit signed immediate value
mov (D11) movhi (D12)
move register to register move immediate into high halfword
Description: Moves the contents of rA to rC. Description: Writes the immediate value IMMED into the
Operation: rC ← rA high halfword of rB, and clears the lower halfword of rB to
Assembler Syntax: mov rC,rA 0x0000.
Example: mov r6,r7 Usage: The maximum allowed value of IMMED is 65535.
Pseudo-instruction: mov is implemented as add rC, rA, r0. The minimum allowed value is 0. To load a 32-bit constant
movi (D13) into a register, first load the upper 16 bits using a movhi
move signed immediate into word pseudo-instruction. The%hi() macro can be used to extract
Description: Sign-extends the immediate value IMMED to the upper 16 bits of a constant or a label. Then, load the
32 bits and writes it to rB. lower 16 bits with an ori instruction. The%lo() macro can
Usage: The maximum allowed value of IMMED is 32767. be used to extract the lower 16 bits of a constant or label as
The minimum allowed value is –32768. To load a 32-bit shown below.
constant into a register, refer to the movhi instruction. movhi rB, %hi (value)
Operation: rB ← σ (IMMED) ori rB, rB, %lo (value)
Assembler Syntax: movi rB,IMMED An alternative method to load a 32-bit constant into a
Example: movi r6,-30 register uses the%hiadj() macro and the addi instruction as
Pseudo-instruction: movi is implemented as shown below.
addi rB, r0, IMMED. movhi rB, %hiadj (value)
addi rB, rB, %lo (value)
Operation: rB ← (IMMED : 0x0000)
Assembler Syntax: movhi rB,IMMED
Example: movhi r6,0x8000
Pseudo-instruction: movhi is implemented as
orhi rB, r0, IMMED.
movia (D14) mul (D16)
move immediate address into word multiply
Description: Writes the address of label to rB. Description: Multiplies rA times rB and stores the 32 low-
Operation: rB ←label order bits of the product to rC. The result is the same
Assembler Syntax: movia rB,label whether the operands are treated as signed or unsigned
73
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
74
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
75
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
76
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
77
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
78
Khoa Điện tử – Viễn thông THỰC HÀNH CẤU TRÚC MÁY TÍNH
Bộ môn Máy tính – Hệ thống nhúng
Description: Copies the value of rA in the current register Description: Calculates the bitwise logical exclusive-or of
set to rC in the previous register set. This instruction can rA and rB and stores the result in rC.
set r0 to 0 in a shadow register set. Operation: rC ← rA ^ rB
Usage: The previous register set is specified by status.PRS. Assembler Syntax: xor rC, rA, rB
By default, status.PRS indicates the register set in use Example: xor r6, r7, r8
before an exception, such as an external interrupt, caused a Exceptions: None
register set change. Instruction Type: R
To write to an arbitrary register set, software can insert the Instruction Fields: A = Register index of operand rA
desired register set number in status.PRS prior to executing B = Register index of operand rB
wrprs. C = Register index of operand rC
System software must use wrprs to initialize r0 to 0 in each
shadow register set before using that register set. If shadow
register sets are not implemented on the NiosII core, wrprs
is an illegal instruction.
Operation: prs.rC ← rA
Assembler Syntax: wrprs rC, rA
Example: wrprs r6, r7
Exceptions: Supervisor-only instruction
Illegal instruction
Instruction Type: R
Instruction Fields: A = Register index of operand rA
C = Register index of operand rC
xorhi (G1)
xori (G2)
bitwise logical exclusive or immediate into high
bitwise logical exclusive or immediate
halfword
Description: Calculates the bitwise logical exclusive XOR Description: Calculates the bitwise logical exclusive OR of
of rA and (IMM16 : 0x0000) and stores the result in rB. rA and (0x0000 : IMM16) and stores the result in rB.
Operation: rB ← rA ^ (IMM16 : 0x0000) Operation: rB ← rA ^ (0x0000 : IMM16)
Assembler Syntax: xorhi rB, rA, IMM16 Assembler Syntax: xori rB, rA, IMM16
Example: xorhi r6, r7, 100 Example: xori r6, r7, 100
Exceptions: None Exceptions: None
Instruction Type: I Instruction Type: I
Instruction Fields: A = Register index of operand rA Instruction Fields: A = Register index of operand rA
B = Register index of operand rB B = Register index of operand rB
IMM16 = 16-bit unsigned immediate value IMM16 = 16-bit unsigned immediate value
79