2006/12/28

Draft

32-bit general-purpose registers:
  R0 ~ RD, stack pointer SP (RE), base pointer BP (RF)
  RAb, RAw, RA correspond to x86's al, ax, eax, respectively
  R0 always 0

flags register: FR
  flags: zero, carry, overflow, signed

program counter: PC

instruction register: IR

8-bit opcode

12-bit memory address, 1-byte per addressable unit
2^12 = 4096 bytes of memory in total
0xFFC ~ 0xFFF as the stdio port

variable-length instruction (at most 32-bit)

an adder and a shifter between register file and ALU
to support stack / procedure operations and addressing mode

instruction set:

  hlt

  ; ALU operations (20)
  ; affects FR except inc & dec, RC may be a constant
  ; always performs 32-bit calculation
  add RA, RB, RC  ; RA <- RB + RC
  sub RA, RB, RC  ; RA <- RB - RC
  and RA, RB, RC  ; RA <- RB & RC
  or  RA, RB, RC  ; RA <- RB | RC
  xor RA, RB, RC  ; RA <- RB ^ RC
  shl RA, RB, RC  ; RA <- RB << RC
  shr RA, RB, RC  ; RA <- RB >> RC
  not RA, RC      ; RA <- ~RC
  inc RA, RC      ; RA <- RC + 1
  dec RA, RC      ; RA <- RC - 1
  
  ; data transfer operations (9)
  ; ldi & sti are integrated into ld & st
  ; RA may be replaced by RAb or RAw
  lea RA, addr + RB + RC * c  ; RA <- addr + RB + RC * c, 3 versions
  ld  RA, addr + RB + RC * c  ; RA <- [addr + RB + RC * c], 3 versions
  st  RA, addr + RB + RC * c  ; [addr + RB + RC * c] <- RA, 3 versions

  ; jump operations (19)
  jz  addr  ; jump if zero
  jnz addr  ; jump if not zero
  jc  addr  ; jump if carry
  jnc addr  ; jump if not carry
  jo  addr  ; jump if overflow
  jno addr  ; jump if not overflow
  js  addr  ; jump if signed
  jns addr  ; jump if not signed
  je  addr  ; jump if equal
  jne addr  ; jump if not equal
  ja  addr  ; jump if above
  jna addr  ; jump if not above
  jb  addr  ; jump if below
  jnb addr  ; jump if not below
  jg  addr  ; jump if greater
  jng addr  ; jump if not greater
  jl  addr  ; jump if less
  jnl addr  ; jump if not less
  jmp addr  ; unconditional jump

  ; stack operations (8)
  ; RA may be replaced by RAb or RAw
  push RA  ; SP -= 4, [SP] <- RA, 3 versions
  pop  RA  ; RA <- [SP], SP += 4, 3 versions
  pushf    ; --SP, [SP] <- FR
  popf     ; FR <- [SP], ++SP

  ; procedure operations (2)
  call addr  ; SP -= 4, [SP] <- PC, jmp addr
  ret        ; PC <- [SP], SP += 4

--
只是草稿 XD。

Labels:

<< 回到主頁