NEC V30MZ: Difference between revisions

From WSdev Wiki
Jump to navigationJump to search
No edit summary
(move sections out to sub-pages)
 
Line 3: Line 3:
Unlike the NEC V20/V30 CPU family, the V30MZ is fully compatible with the Intel 80186's documented behaviour, as well as some of its undocumented behaviour (such as the SALC opcode); it also omits the V20/V30's opcode extensions.
Unlike the NEC V20/V30 CPU family, the V30MZ is fully compatible with the Intel 80186's documented behaviour, as well as some of its undocumented behaviour (such as the SALC opcode); it also omits the V20/V30's opcode extensions.


The NEC V30MZ datasheet uses distinct names for opcodes and registers (''NEC names''); as all homebrew compilers and assemblers for the platform utilize Intel's official naming (''Intel names''), the latter is what the wiki - and most community tooling - has standardized on.
== Format ==


== Architecture ==
The NEC V30MZ datasheet provides distinct names for opcodes, flags and registers, which the wiki refers to as ''NEC names''. As all homebrew compilers and assemblers for the platform utilize Intel's official naming (''Intel names''), the latter is what is used throughout. For registers and flags, distinct NEC names are presented in the following format: Intel<sup>NEC</sup>.


For this section, elements of the architecture which have distinct NEC names are provided in the following format: Intel<sup>NEC</sup>.
== Sections ==


=== Registers ===
* [[NEC V30MZ registers]]
 
* [[NEC V30MZ flags]]
* Four 16-bit general-purpose registers, with their (low, high) components accessible as individual 8-bit sub-registers:
* [[NEC V30MZ instruction set]]
** '''AX'''<sup>AW</sup> ('''AL''', '''AH''') - the ''accumulator'' register,
* [[NEC V30MZ interrupts]]
** '''BX'''<sup>BW</sup> ('''BL''', '''BH''') - the ''base'' register,
** '''CX'''<sup>CW</sup> ('''CL''', '''CH''') - the ''count'' register,
** '''DX'''<sup>DW</sup> ('''DL''', '''DH''') - the ''data'' register,
* Four additional 16-bit registers:
** '''SI'''<sup>IX</sup> - the ''source index'' register,
** '''DI'''<sup>IY</sup> - the ''destination index'' register,
** '''SP''' - the ''stack pointer''; the stack is always addressed in the stack segment (so as <code>SS:SP</code> far addresses),
** '''BP''' - the ''base pointer''.
* Four segment registers:
** '''CS'''<sup>PS</sup> - the ''code segment'',
** '''DS'''<sup>DS0</sup> - the ''data segment'',
** '''ES'''<sup>DS1</sup> - the ''extra segment''; an additional data segment,
** '''SS''' - the ''stack segment''.
* '''IP'''<sup>PC</sup> - the ''instruction pointer''; instructions are always addressed in the code segment (so as <code>CS:IP</code> far addresses),
* '''FLAGS'''<sup>PSW</sup> - the 16-bit processor flag register.
 
While the eight registers can be used in a general-purpose manner, some opcodes are constrained to only using certain registers:
 
* '''AX''' benefits from more compact encoding for certain instructions; it's also used as an output and input register in multiplication/division, port access, BCD conversions, and (as AL) in the XCHG opcode.
* '''CX''' is used for loop and repeat instructions as a counter.
* '''DX''' can be used used as the address register for port access, it is also used as an output register for word multiplication/division.
* '''BX''', '''SI''', and '''DI''' can be used as indices for accessing data in tables in the DS segment (or other segments when overridden).
** '''SI''' and '''DI''' are, in addition, used as source and destination pointers by string instructions.
* Similarly, '''BP''' can be used as an index for accessing stack data; this makes it particularly useful as a frame pointer.
 
=== Flags ===
 
The V30MZ features the following flags:
 
15  bit  8  7  bit  0
  ---- ----  ---- ----
  m111 odit  sz0a 0p1c
  |    ||||  || |  | |
  |    ||||  || |  | +- Carry (CF<sup>CY</sup>)
  |    ||||  || |  +--- Parity (PF<sup>P</sup>)
  |    ||||  || +------ Auxillary Carry (AF<sup>AC</sup>)
  |    ||||  |+-------- Zero (Z)
  |    ||||  +--------- Sign (S)
  |    |||+------------ Single Step<sup>Break</sup> (TF<sup>BRK</sup>)
  |    ||+------------- Interrupt Enable (IF<sup>IE</sup>)
  |    |+-------------- Direction (DF<sup>DIR</sup>)
  |    +--------------- Overflow (OF<sup>V</sup>)
  +-------------------- Mode (MD)
 
In general, they are set by operations as follows:
 
* '''Carry''' - stores the carry/borrow state of the last arithmetic operation, or the bit shifted to it for shift/rotate operations.
* '''Parity''' - set to <tt>1</tt> if, after arithmetic and logical operations, the lower 8 bits of the result are even.
* '''Auxillary Carry''' - stores the carry state from the lower 4-bit nibble (bits 0-3) to the higher 4-bit nibble (bits 4-7), or the borrow state from the higher nibble to the lower nibble.
* '''Zero''' - set to <tt>1</tt> if, after arithmetic and logical operations, the result is equal to zero.
* '''Sign''' - set to <tt>1</tt> if, after arithmetic and logical operations, the highest bit of the result is set.
* '''Overflow''' - set to <tt>1</tt> if an overflow occured as part of the arithmetic operation.
 
There are also programmer-controlled control flags:
 
* '''Single Step''' - if set to <tt>1</tt>, after every instruction, a software interrupt (vector 1) is generated.
* '''Interrupt Enable''' - if set to <tt>1</tt>, enables maskable interrupt handling via the interrupt vector table; cleared to <tt>0</tt> as part of interrupt handling and restored by the <tt>IRET</tt> opcode.
* '''Direction''' - if set to <tt>1</tt>, string instructions decrement pointers as part of their operation; if set to <tt>0</tt>, the pointers are to be incremented.
* '''Mode''' - used for 8080 emulation mode in other V20/V30-family chips, does nothing on V30MZ
 
<!--
 
== Instruction set ==
 
{| class="wikitable sortable"
|+ V30MZ Instruction Set
|-
! Instruction
! Opcode (hex)
! Opcode (bin)
! Bytes
! Cycles
! Flags
! NEC mnemonic
! Notes
|-
| <tt>ADD AL, imm8</tt>
| <tt>04</tt>
| <tt>00000100</tt>
| 2
| 1
| <tt>O...SZAPC</tt>
| <tt>ADD AL, imm8</tt>
|
|-
| <tt>ADD AX, imm16</tt>
| <tt>05</tt>
| <tt>00000101</tt>
| 3
| 1
| <tt>O...SZAPC</tt>
| <tt>ADD AW, imm16</tt>
|
|-
| <tt>ADD mem8, imm8</tt>
| <tt>80 rm</tt> / <tt>82 rm</tt>
| <tt>100000.0 oo000mm</tt>
| 3-5
| 3
| <tt>O...SZAPC</tt>
| <tt>ADD mem8, imm8</tt>
|
|-
|}
 
-->


== Links ==
== Links ==

Latest revision as of 09:38, 5 August 2024

The NEC V30MZ is the CPU component of the WonderSwan SoC.

Unlike the NEC V20/V30 CPU family, the V30MZ is fully compatible with the Intel 80186's documented behaviour, as well as some of its undocumented behaviour (such as the SALC opcode); it also omits the V20/V30's opcode extensions.

Format

The NEC V30MZ datasheet provides distinct names for opcodes, flags and registers, which the wiki refers to as NEC names. As all homebrew compilers and assemblers for the platform utilize Intel's official naming (Intel names), the latter is what is used throughout. For registers and flags, distinct NEC names are presented in the following format: IntelNEC.

Sections

Links