umx_asm

UMX virtual machine assembly compiler
git clone git://bsandro.tech/umx_asm
Log | Files | Refs | README | LICENSE

register.go (375B)


      1 package asm
      2 
      3 import (
      4 	"log"
      5 	"strconv"
      6 )
      7 
      8 type Register uint8
      9 
     10 func (r Register) String() string {
     11 	return strconv.Itoa(int(r))
     12 }
     13 
     14 func NewRegister(input string) Register {
     15 	val, err := strconv.ParseUint(input, 10, 8)
     16 	if err != nil {
     17 		log.Fatal(err)
     18 	}
     19 	if val >= 8 { // only 8 registers allowed
     20 		log.Fatalf("invalid register #%d", val)
     21 	}
     22 	return Register(uint8(val))
     23 }