flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Non-x86 architectures > [ARM] OS/Graphics/UI. Magic-Compiler+Emulator. 8 Examples

Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
[ARM] OS/Graphics/UI. Magic-Compiler+Emulator. 8 Examples
Magic-Compiler + 8 Examples for the PL110 ARM Primecell Color LCD Controller.

Visual UI/interfaces/controls. High resolution fonts and icons. Drawing works with any display that supports RGB 16 5.6.5 (example: Raspberry PI).

Download: Magic-Compiler Package (8MB ZIP due to QEMU).

Source code is compatible with FASMARM (included in \BINARY\). No setup. All \EXAMPLES\ and \PROJECTS\ compile+run where they are located and they all have shared access to \MEDIA\ files. To run an example, click NAME.BAT. QEMU works most of the time. If it fails (black screen, "Stopped"), just retry. LANGUAGE.INC is never finished, always under construction. No input. I couldn't find any information online for this device except for ARM's documents and QEMU's source code. Preview:

Code:
; address &vga[(y*(screen.w*2))+(x*2)]...

function vga.xy.16
  . a3=SCREEN.PITCHa4=a2*a3
  . a4+(a1<<1), a2=VGAa1=a2+a4
endf

; erase screen with color/a1...

function clear.screen.16
  alias vga=a3,\
   w=a2c=a1
  . vga=VGAw=SCREEN.N
  .repeat w
    . (u16) *vga++=c
  .endr
endf

; create rgb16: a1/a2/a3 = 0-31/0-63/0-31

function rgb16
  alias r=a1g=a2b=a3
  . r&11111bg&111111bb&11111b
  . r<<11r|(g<<5), r|b
endf

; extract r/g/b 16

function get.rgb16
  alias r=a1g=a2b=a3c=a4
  . c=rr=c>>11r&11111bg=c>>5
  . g&111111bb=c&11111b
endf

; draw pixel: a1-a3=x/y/c...

function draw.pixel.16
  alias vga=a1c=v1
  . c=a3
  vga.xy
  . (u16) *vga=c
endf

; draw horizontal line: a1-a4=x/y/w/c...

function draw.line.h.16
  alias vga=a1c=v1w=v2
  . c=a4w=a3
  vga.xy
  .repeat w
    . (u16) *vga++=c
  .endr
endf

; draw solid rectangle: a1-v1=x/y/w/h/c...

function draw.box.16
  alias vga=a1c=v1,\
   sw=v2w=v3h=v4,\
   pitch=a2wb=a3
  . w=a3sw=wh=a4    ; save w/h
  vga.xy
  . pitch=SCREEN.PITCH  ; screen+row
  . wb=w<<1             ; w in bytes
  .repeat h             ; h # times
    . w=sw              ; reset saved
    .repeat w           ; w # times
      . (u16) *vga++=c  ; copy color
    .endr
    . vga+pitchvga-wb ; advance
  .endr
endf

; draw rectangle outline...

function draw.outline.16
  alias c=v1,\
   x=v2y=v3w=v4h=v5
  . x=a1y=a2w=a3h=a4
  vga.xy
  draw.line.h xywc     ; top: x, y, w
  draw.line.v xyhc     ; left: x, y, h
  . a1=x+wa1--             ; right: x+w-1
  . a2=y+1a3=h-1           ; y+1, h-1
  draw.line.v a1a2a3c
  . a1=xa2=y+ha2--       ; bottom: y+h-1
  draw.line.h a1a2wc
endf

; draw rectangle with transparency...
; a1-a4=x/y/w/h. v5=color, v6=alpha

function draw.box.t.16
  alias vga=a1c=v1,\
   w=v3h=v4sw=v2,\
   cl=v5a=v6,\
   pitch=a2,\
   wb=a3sc=v7
  . w=a3sw=wh=a4    ; save w/h
  vga.xy
  . pitch=SCREEN.PITCH  ; screen+row
  . wb=w<<1             ; w in bytes
  .repeat h             ; h # times
    . w=sw              ; reset saved
    .repeat w           ; w # times
     . (u16c=*vga     ; screen color
      pusha
      mix ccla      ; combine
      . c=a1
      popa
      . (u16) *vga++=c  ; copy
    .endr
    . vga+pitchvga-wb ; advance
  .endr
endf

; draw 16BPP scanline. a1-a3/v1=x/y/w/pixels...

function draw.scanline.16
  alias vga=a1,\          ; aliases
   p=v1w=v2
  . w=a3                  ; save w
  vga.xy                  ; &vga(x,y)
  .repeat w               ; w # times
    . (u16) *vga++=*p++   ; copy pixel
  .endr
endf

; draw with transparent color...

function draw.scanline.t.16
  alias vga=a1,\     ; aliases
   c=a2key=v2,\
   w=v3p=v1
  . w=a3p=a4       ; save w/p
  vga.xy             ; &vga(x,y)
   . (u16key=*p    ; color at 0x0
  .repeat w          ; w # times
    . (u16c=*p++   ; get source pixel
    .if c<>key       ; opaque?
      . (u16) *vga=c ; copy to screen
    .end
    . vga+2          ; next
  .endr
endf

; draw 16BPP variant scanline.
; a1-v1=x/y/w/c/pixels...

function draw.scanline.v.16
  alias vga=a1,\       ; aliases
   p=v1c=v2s=v3,\
   cl=v4x=v5w=v6,\
   n=v7
  . w=a3cl=a4        ; save w, color
  vga.xy               ; &vga(x,y)
  .repeat w            ; w # times
    . (u16c=*p++     ; get source pixel
    .if c=0            ; black, 100% invisible
      go .next
    .end
    . x=WHITE
    .if c=x            ; white, 100% visible
      . c=cl
      go .draw
    .end
    . (u16s=*vga     ; else mixed
    . n=c&11111bn<<3 ; alpha intensity
    .if n>=252         ; invisible
      go .next         ; skip
    .end
    .if n<=4           ; pure
      . c=cl
      go .draw
    .end
    pusha
    mix scln       ; combine
    . c=r0             ; screen+color
    popa
    .draw:
    . (u16) *vga=c
    .next:
    . vga+2            ; next
  .endr
endf

; draw bitmap with transparency
; by upper left pixel color (0x0).
; a1-a4=x/y/w/h. v1=pixels...

function draw.bitmap.t.16
  alias \                 ; aliases
   vga=a1image=v1,\
   w=v2h=v3sw=v4,\    ; sizes, saved w
   pitch=v5iwb=v6,\
   key=v7c=a2
  . w=a3h=a4sw=w      ; save size
  . pitch=SCREEN.PITCH    ; screen+image
  . iwb=w<<1              ; w in bytes
  . (u16key=*image      ; transparent color
  vga.xy                  ; &vga(x,y)
  .repeat h               ; h # times
    . w=sw
    .repeat w             ; w # times
      . (u16c=*image++
      .if c<>key          ; opaque?
        . (u16) *vga++=c  ; copy pixel
      .else
        . vga+2           ; next
      .end
    .endr
    . vga+pitchvga-iwb  ; advance
  .endr
endf

; draw bitmap with alpha in v8

function draw.bitmap.a.16
  alias \                 ; aliases
   vga=a1image=v1,\
   w=v2h=v3sw=v4,\    ; sizes, saved w
   pitch=v5iwb=v6,\
   key=v7a=v8c=r12
  . w=a3h=a4sw=w      ; save size
  . pitch=SCREEN.PITCH    ; screen+image
  . iwb=w<<1              ; w in bytes
  . (u16key=*image      ; transparent color
  vga.xy                  ; &vga(x,y)
  .repeat h               ; h # times
    . w=sw
    .repeat w             ; w # times
      . (u16c=*image++
      .if c<>key          ; opaque?
        pusha
        . (u16a2=*vga
        . a1=ca3=a
        mix
        . c=a1
        popa
        . (u16) *vga++=c  ; copy pixel
      .else
        . vga+2           ; next
      .end
    .endr
    . vga+pitchvga-iwb  ; advance
  .endr
endf

; mix(a, b, n) - alpha combination. colors:
; a1/a2=a/b. intensity: a3/n=0-31

function mix.rgb16
  alias \
   a=a1b=a2,\
   n=a3d=a4,\
   x=v1s=v2,\
  sr=v3sg=v4sb=v5
  . d=a>>>11d&1Fh   ; dr=(c1>>11)&11111b
  . s=b>>>11s&1Fh   ; sr=(c2>>11)&11111b
  . s-ds*ns>>>8   ; ((sr-dr)*n)>>8)+dr
  . sr=s+d
  . d=a>>>5d&3Fh    ; dg=(c1>>5)&111111b
  . s=b>>>5s&3Fh    ; sg=(c2>>5)&111111b
  . s-ds*ns>>>8   ; ((sg-dg)*n)>>8)+dg
  . sg=s+d
  . d=a&1Fhs=b&1Fh  ; db=c1&11111b
  . s-ds*ns>>>8   ; ((sb-db)*n)>>8)+db
  . sb=s+d
  . a=sr<<11          ; c=(r<<11)|(g<<5)|b
  . a|(sg<<5), a|sb
endf

; memory.copy(destiny, source, count)

function memory.copyabn
  cmp a34         ; if n<4
  blt .8            ; copy 8BIT
  mov v2a3lsr 2 ; v2=n/4
  .32:              ; copy 32BIT
   ldr v1, [a2], 4  ; v1=*a2++
   str v1, [a1], 4  ; *a1++=v1
   subs v21       ; v2 # times
  bne .32
  ands a33        ; modulo 4
  beq .!            ; remainder?
  .8:               ; copy 8BIT
   ldrb v1, [a2], 1 ; v1=*a2++
   strb v1, [a1], 1 ; *a1++=v1
   subs a31       ; a3 # times
  bne .8
endf

; text.n(t) - get text length, # characters

function text.n
  alias t=a1b=a2c=v1
  . c=1b=t
  .while c           ; until 0
    . (u8c=*t++    ; read c
  .endw
  . t--, t-b         ; return current-start
endf

; text.copy(a, b) - standard copy with 0 after

function text.copy
  alias a=a1b=a2c=v1
  . c=1
  .while c
    . (u8c=*b++    ; read
    . (u8) *a++=c    ; copy
  .endw
  . a--              ; return end
endf

; text.attach(a, b) - attach b to a

function text.attach
  alias a=a1,\
   b=a2p=v1
  . p=b
  text.end
  . b=p
  text.copy
endf

; text.attach.c(t, c) - attach c to t

function text.attach.c
  alias t=a1c=v2
  . c=a2
  text.end
  . (u8) *t++=c, (u8) *t=0
endf

; text.compare(a, b) - lexical comparison.
; return <0>

function text.compare
  alias a=a1b=a2,\
   c=v1d=v2
   . c=1d=c
  .while c=d         ; while equal
    . (u8c=*a++
    . (u8d=*b++
    . c|d            ; and both nonzero
    .breakz          ; break if either=0
  .endw
  . a=c-d            ; return *a-*b
endf

; text.equal(a, b) - equal? return 1/0

function text.equal
  text.compare
  .if false
    return 1
  .end
endf 0

; text.find(t, c) - search for character.
; return address or 0

function text.find
  alias t=a1,\
   c=v1key=a2
  .forever           ; loop
    . (u8c=*t      ; read c
    .if c=0          ; end?
      return 0       ; not found
    .end
    .if c=key        ; found?
      return t       ; t=address
    .end
    . t++            ; next
  .endfv
endf

; text.find.last(t, c) - search for c reverse

function text.find.last
  alias t=a1c=a2,\
   key=v1p=v2
  . key=cp=t       ; save begin
  . c=1
  .while c           ; advance to end-1,
    . (u8c=*t++    ; last character
  .endw
  . t-2
  .while t>p         ; loop backwards
    . (u8c=*t      ; until beginning
    .if c=key        ; found
      return t       ; t=address
    .end
    . t--            ; previous
  .endw
endf 0               ; not found

(Keywords for search engines to bring in new users: ARM assembler tutorial qemu bare metal asm instructions source code data example raspberry PI macro language assembler ARM X86 dex dexbasic hla rosasm assembler download if .if while .while loop let high level features raspberry PI RPI bare metal string graphics art font icon draw pixel image bitmap font converter file I/O input output memory manager card flash RiscOS raspbian programming ARM ASM assembler assembly tutorials how to learn introduction beginner manual bare metal GBA header gameboy advance SP raspberry pi instruction reference encodings list decode register memory ip sp lr pc load relative mov ldr adr immediate constant direct absolute address branch pipeline cache alu THUMB 1 2 FPA VFP SIMD NEON vector floating point FP FPA bios interrupt coprocessor emulator disassembler ARM simulator ARM keil DS-5 armulator PDF manual raspberry pi RPI raspberry pi RPI raspberry pi RPI raspberry pi RPI OS OS OS example source code tutorials DexOS Dex BASIC DexBASIC raspberry PI macro language assembler ARM X86 if .if while .while loop let high level features raspberry PI RPI RISC OS ARM bare metal string drawing graphics art font icon draw pixel image bitmap font converter file I/O input output memory manager card format address org start code data flash RiscOS raspbian install raspbian RPI programming ARM ASM assembler assembly tutorials how to learn introduction beginner manual bare metal GBA header gameboy advance SP raspberry pi instruction reference encode encodings list decode register memory ip sp lr pc load relative mov ldr adr immediate constant address branch pipeline cache alu T1 T2 THUMB 1 2 FPA VFP SIMD NEON vector floating point FP FPA bios interrupt coprocessor emulator disassembler simulator ARM keil DS-5 armulator PDF manual raspberry pi RPI raspberry pi RPI raspberry pi RPI raspberry pi RPI OS OS OS example source code tutorials ARM ASM assembler assembly tutorials how to learn introduction beginner ARM ASM assembler assembly tutorials how to learn introduction beginner)


Description: Zionos Operating System. EXAMPLES\ZOS\ZOS.BAT
Filesize: 179.48 KB
Viewed: 6327 Time(s)

zionos.jpg




Last edited by m3ntal on 12 Mar 2014, 07:47; edited 3 times in total
Post 07 Mar 2014, 16:43
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Z-IDE design in 640x480. Intended for higher resolutions, W/XGA+. To run, click EXAMPLES\ZIDE\ZIDE.BAT.


Description:
Filesize: 118.26 KB
Viewed: 6324 Time(s)

zidemc.jpg


Post 07 Mar 2014, 16:46
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
7 examples + 3 project templates:


Description:
Filesize: 159.76 KB
Viewed: 6324 Time(s)

previews.jpg


Post 07 Mar 2014, 16:47
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Magic-Compiler with syntax highlighting:


Description:
Filesize: 284.31 KB
Viewed: 6318 Time(s)

magic.jpg


Post 07 Mar 2014, 16:48
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Update: I registered with sourceforge.net and updated download link.

My New SourceForge Page
Post 08 Mar 2014, 20:06
View user's profile Send private message Reply with quote
Gyver



Joined: 13 Jul 2009
Posts: 3
Mouse doesn' t work on my system : Win 8.1 pro 64 bit Crying or Very sad
Post 09 Mar 2014, 10:40
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
Gyver: Sorry, no input.

QEMU supports serial+USB mouse+keyboard, but I can't find any information on how to initialize devices, setup interrupts and send/receive data. From ARM's documents, I managed to initialize the LCD and access a linear VGA. QEMU also supports Angel-ARM interrupts - see QEMU\TARGET-ARM\ARM-SEMI.C - so file I/O should be easy.


Last edited by m3ntal on 12 Mar 2014, 07:30; edited 1 time in total
Post 10 Mar 2014, 03:24
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
UPDATE (3/12/14)

* Download Magic-Compiler. New Angel-ARM, FILE.ASM example, FILE.INC, open/create/read/write/seek/etc, CONSOLE.INC, more testing, functions with fast-call parameters (TEXT+DRAW is reduced and clearer), removed DRAW.INC suffixes. Fix: text.find.last.

\EXAMPLES\FILE\FILE.ASM: 100% portable.

Code:
text title.t='Angel-ARM',\
 name='EXAMPLE.TXT',\
 output='ABCDEFGHIJ',\
 error.t='File I/O failed'
size=output.$

main
  puts name
  putr
  get.filename name
  puts filename
  putr
  create filename
  .if false
    go .error
  .end
  text.copy bufferoutput
  text.reverse buffer
  write buffersize
  .if false
    go .error
  .end
  close
  open filename
  .if false
    go .error
  .end
  read buffersize
  .if false
    go .error
  .end
  puts buffer
  text.reverse buffer
  puts buffer
  go .ok
  .error:
  puts error.t
  .ok:
  close
  draw.console
endm

Post 12 Mar 2014, 07:27
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
New: Convert text to number (i/u/h/b):

Code:
; convert text to unsigned 32BIT integer

function t2ut
  alias t=v1,\
   c=v2n=v3
  . t=a1, (u8c=*t
  .if c=30h           ; skip preceding
    .while c=30h      ; '0's...
      . (u8c=*t++
    .endw
    . t--
  .end
  .if c=0             ; 0 value?
    return 0
  .end
  . n=0
  .forever
    . (u8c=*t++
    .if c=0
      return n
    .end
    . n+(n<<2), n+n   ; n=n*10+*t++-'0'
    . n-30hn+c
  .endfv
endf n

; convert text to signed 32BIT integer

function t2it
  alias t=v1,\
   c=v2negate=v3
  . t=a1, (u8c=*t
  . negate=0
  .if c='-'           ; negative?
    . t++, negate=1   ; skip
  .end
  t2u t
  .if negate
    . -a1
  .end
endf

; convert hexadecimal text to number

function t2ht       ; text to hexadecimal
  alias t=v1,\
   c=v2n=v3
  . t=a1, (u8c=*t
  .if c=30h           ; skip preceding
    .while c=30h      ; '0's...
      . (u8c=*t++
    .endw
    . t--
  .end
  .if c=0             ; 0 value?
    return 0
  .end
  . n=0
  .forever
    . (u8c=*t++
    .if c=0
      return n
    .end
    . n<<4            ; n=n*16+c2h(*t++)
    .if c<=39h        ; 0-9
      . c-30h
    .else.if c>=97    ; a-f
      . c-57h
    .else             ; A-F
      . c-37h
    .end
    . n+c
  .endfv
endf n

; convert binary text to number

function t2bt       ; text to binary
  alias t=v1,\
   c=v2n=v3
  . t=a1, (u8c=*t
  .if c=30h           ; skip preceding
    .while c=30h      ; '0's...
      . (u8c=*t++
    .endw
    . t--
  .end
  .if c=0             ; 0 value?
    return 0
  .end
  . n=0
  .forever
    . (u8c=*t++
    .if c=0
      return n
    .end
    . n<<1n+c       ; n=n*2+*t++-'0'
    . n-30h
  .endfv
endf n

Parse: Source, token. Skip/copy while/until:

Code:
;;;;;;;;;;;;;;;;;;; PARSE TEXT ;;;;;;;;;;;;;;;;;;;

; skip while type and not 0

; get p=text.skip.while p, C.WHITE

function text.skip.whilettype
  alias t=a1,\
   type=a2c=a3p=a4
  .forever
    . (u8c=*t
    .if c=0
      return 0
    .end
    . p=TLTp+c
    . (u8c=*pc&type
    .breakz
    . t++
  .endfv
  . (u8c=*t
  .if c=0
    return 0
  .end
endf

; skip until type and while not 0

; get p=text.skip.until p, C.RETURN

function text.skip.untilttype
  alias t=a1,\
   type=a2c=a3p=a4
  .forever
    . (u8c=*t
    .if c=0
      return 0
    .end
    . p=TLTp+c
    . (u8c=*pc&type
    .breakn
    . t++
  .endfv
  . (u8c=*t
  .if c=0
    return 0
  .end
endf

; copy while type and not 0

; get s=text.copy.while t, s, C.NAME

function text.copy.whileabtype
  alias a=a1b=a2,\
   type=a3c=a4p=v1
  .forever
    . (u8c=*b
    .if c=0
      go .e
    .end
    . p=TLTp+c
    . (u8c=*pc&type
    .breakz
    . (u8) *a++=*b++
  .endfv
  .e:
  . (u8) *a=0, (u8c=*b
  .if c=0
    return 0
  .end
endf b

; copy until type and while not 0

; get s=text.copy.until t, s, C.END

function text.copy.untilabtype
  alias a=a1b=a2,\
   type=a3c=a4p=v1
  .forever
    . (u8c=*b
    .if c=0
      return 0
    .end
    . p=TLTp+c
    . (u8c=*pc&type
    .breakn
    . (u8) *a++=*b++
  .endfv
  . (u8) *a=0, (u8c=*b
  .if c=0
    return 0
  .end
endf b

;;;;;;;;;;;;;;;;;; SOURCE, TOKEN ;;;;;;;;;;;;;;;;;

; safer, easier global skip/copy while/until

align 4

void source.ptoken.p
integer token.typetoken.valuetoken.size

macro set.source r
 { . r12=source.pr11=r, (u32) *r12=r11 }

macro set.token r
 { . r12=token.pr11=r, (u32) *r12=r11 }

macro set.stream st {
  set.source s
  set.token t
}

macro get.source st {
  . s=source.p, (u32s=*s
  if ~t eq
    . t=token.p, (u32t=*t
  end if
}

macro get.token.p t
 { . t=token.p, (u32t=*t }

macro set.token.x xv
 {  . r12=token#xr11=v, (u32) *r12=r11 }

macro set.token.type v { set.token.x .typev }
macro set.token.class v { set.token.x .classv }
macro set.token.value v { set.token.x .valuev }

macro get.token.value x
. x=token.value, (u32x=*x }

; skip/copy while/until type...

function skip.whiletype
  alias p=v1type=v2
  . type=a1
  get.source p
  try p=text.skip.while ptype
  set.source p
endf p

function skip.untiltype
  alias p=v1type=v2
  . type=a1
  get.source p
  try p=text.skip.until ptype
  set.source p
endf p

function copy.whiletype
  alias p=v1t=v2type=v3
  . type=a1
  get.source pt
  try p=text.copy.while tptype
  set.source p
endf p

function copy.untiltype
  alias p=v1t=v2type=v3
  . type=a1
  get.source pt
  try p=text.copy.until tptype
  set.source p
endf p

macro skip.space   { skip.while C.SPACE }
macro skip.white   { skip.while C.WHITE }
macro skip.comment { skip.until C.RETURN }

function skip.all
  alias s=v1c=v2
  .white:
  try skip.white
  get.source s
  . (u8c=*s
  .if c=0
    return 0
  .end
  .if c=SEMI.C
    try skip.comment
    go .white
  .end
endf 1

; skip spaces then character. return 0
; if next c not key

function skip.ckey
  alias p=v1,\
   c=v2key=v3
  . key=a1
  skip.space
  get.source p
  . (u8c=*p
  .if c<>key
    return 0
  .end
  . p++
  set.source p
endf p

;;;;;;;;;;;;;;;;;;; GET TOKEN ;;;;;;;;;;;;;;;;;;;;

macro get.name   { copy.while C.NAME }
macro get.digits { copy.while C.DIGIT }

function get.number
  alias t=v1s=v2,\
   n=v3c=v4p=v5
  try skip.space
  get.source s
  . (u8c=*s
  .if c<30h           ; must begin
    go .error         ; with 0-9
  .end
  .if c>39h
    go .error
  .end
  get.digits          ; A-F/a-f, h,b,k,m
  get.token.p t
  get p=text.end t    ; get last
  . p--, (u8c=*p    ; c of token
  . (u8) *p=0p++
  .if c>30h           ; ends with
    .if c<39h         ; 0-9?
      get n=t2u t
    .end
  .end
  .if c=68h           ; h/exadecimal
    get n=t2h t
  .else.if c=62h      ; b/inary
    get n=t2b t
  .else.if c=6Bh      ; k/ilobyte
    get n=t2u t
    . n<<10
  .else.if c=6Dh      ; m/egabyte
    get n=t2u t
    . n<<20
  .else
    go .error
  .end
  set.token.type C.NUMBER
  set.token.value n
  return C.NUMBER
  .error:
  syntax.error E.NUMBER
endf 0

function verify.n.xnab
  alias n=a1a=a2b=a3
  .if n>=a
    .if n<=b
      return 1
    .end
  .end
  syntax.error E.VALUE
endf 0

macro verify.i8  { verify.n.x n, -128127 }
macro verify.8   { verify.n.x -255255 }
macro verify.12  { verify.n.x -40954095 }
macro verify.u16 { verify.n.x 00FFFFh }
macro verify.16  { verify.n.x -0FFFFh0FFFFh }
macro verify.i24 { verify.n.x -7FFFFFh7FFFFFh }
macro verify.u24 { verify.n.x 00FFFFFFh }

function get.n.xab
  alias a=v1b=v2n=v3
  . a=a1b=a2
  try get.number
  get.token.value n
  verify.n.x nab
endf 1

macro get.number.i8  { get.n.x -128127 }
macro get.number.8   { get.n.x -255255 }
macro get.number.12  { get.n.x -40954095 }
macro get.number.u16 { get.n.x 00FFFFh }
macro get.number.16  { get.n.x -0FFFFh0FFFFh }
macro get.number.i24 { get.n.x -7FFFFFh7FFFFFh }
macro get.number.u24 { get.n.x 00FFFFFFh }
macro get.number.24  { get.n.x -0FFFFFFh0FFFFFFh }



Preview: Minimal Native ARM Assembler:

Code:
;;;;;;;;;;;;;;;;;; ASSEMBLER.INC ;;;;;;;;;;;;;;;;;

; Native ARM Assembler

align 4

uinteger @ip=10000h,\
 data.offsetdata.size,\
 code.offsetcode.size,\
 in.section

text opcode.name(16),\
 operand.1(96), operand.2(96),\
 operand.3(96), operand.4(96)
integer name.indexopcode.c,\
 opcode.sopcode.key

text label.prefix(32)

texts registers.ta[]='r0''r1''r2''r3',\
 'r4''r5''r6''r7''r8''r9''r10',\
 'r11''r12''r13''r14''r15'

texts registers2.ta[]='a1''a2''a3''a4',\
 'v1''v2''v3''v4''v5''v6''v7',\
 'v8''ip''sp''lr''pc'

numeric C.*,\
 EQNEHSLOMIPLVSVC,\
 HILSGELTGTLEALNV

texts conditions.ta[]=\
 'eq''ne''hs''lo''mi''pl''vs''vc',\
 'hi''ls''ge''lt''gt''le''al''nv'

numeric C.*,\
 EQNEHSLOMIPLVSVC,\
 HILSGELTGTLEALNV

; $ - s/tatus and/or condition
;     example: add/adds/addgt/addsgt
; ? - condition
; @ - action: da, ia, db, ib

textai opcodes.ta,\
 I.ADC='adc$'I.ADD='add$'I.AND='and$',\
 I.ASR='asr$'I.B='b?'I.BFC='bfc?',\
 I.BFI='bfi?'I.BIC='bic$'I.BKPT='bkpt?',\
 I.BL='bl?'I.BLX='blx?'I.BX='bx?',\
 I.CLZ='clz?'I.CMN='cmn$'I.CMP='cmp$',\
 I.CPS='cps'I.EOR='eor$'I.LDC='ldc?',\
 I.LDM='ldm@'I.LDR='ldr?'I.LDRB='ldrb?',\
 I.LDRD='ldrd?'I.LDRH='ldrh?',\
 I.LDRSB='ldrsb?'I.LDRSH='ldrsh?',\
 I.LSL='lsl$'I.LSR='lsr$'I.MCR='mcr?',\
 I.MCRR='mcrr?'I.MLA='mla$'I.MLS='mls?',\
 I.MOV='mov$'I.MOVT='movt?'I.MOVW='movw?',\
 I.MRC='mrc?'I.MRRC='mrrc?'I.MRS='mrs?',\
 I.MSR='msr?'I.MUL='mul$'I.MVN='mvn$',\
 I.NOP='nop'I.ORR='orr$'I.POP='pop?',\
 I.PUSH='push?'I.RBIT='rbit?'I.REV='rev?',\
 I.REV16='rev16?'I.REVSH='revsh?',\
 I.RFE='rfe'I.ROR='ror$'I.RRX='rrx?',\
 I.RSB='rsb$'I.RSC='rsc$'I.SBC='sbc$',\
 I.SBFX='sbfx?'I.SDIV='sdiv'I.SEL='sel?',\
 I.SETEND='setend'I.SMLAL='smlal$',\
 I.SMULL='smull$'I.SRS='srs'I.STC='stc?',\
 I.STM='stm@'I.STR='str?'I.STRB='strb?',\
 I.STRD='strd?'I.STRH='strh?'I.SUB='sub$',\
 I.SWI='swi?'I.SWP='swp?'I.SWPB='swpb?',\
 I.TEQ='teq$'I.TST='tst$'I.UBFX='ubfx?',\
 I.UDIV='udiv'I.UMLAL='umlal$',\
 I.UMULL='umull$'I.UXTB='uxtb?',\
 I.UXTB16='uxtb16?'I.UXTH='uxth?',\
 I.WFE='wfe?'I.WFI='wfi?'I.YIELD='yield?'

;;;;;;;;;;;;;;;;;;;;; ERRORS ;;;;;;;;;;;;;;;;;;;;;

textai errors.ta,\
 E.NONE     ='None',\
 E.SYNTAX   ='Syntax',\
 E.LOAD     ='Load failed',\
 E.UNEXPECT ='Unexpected',\
 E.OPERANDS ='Invalid operand/s',\
 E.AMODE    ='Invalid addressing mode',\
 E.CPU      ='Unsupported by CPU',\
 E.COMMA    =', expected after',\
 E.VALUE    ='Value exceeds size',\
 E.REGISTER ='Register expected',\
 E.NUMBER   ='Number expected',\
 E.NAME     ='Name expected',\
 E.INAME    ='Invalid name',\
 E.RESERVE  ='Reserved name',\
 E.UNDEFINE ='Undefined',\
 E.REDEFINE ='Redefinition',\
 E.EXPECTT  ='Text expected',\
 E.ENDT     ='Text has no end ''',\
 E.MISMATCH ='Mismatched parenthesis'

Convert Instructions:

Code:
.if name=I.NOP
    . i=0E1A00000h
    go .ok
  .end

  .if name=I.BKPT
    try get.number.u16
    get.token.value n
    . i=0E1200000h
    . x=n>>4c=0FFFhx&cx<<8
    . i|xx=n&0Fhi|xi|1110000b
    go .ok
  .end

  .if name=I.SWI
    try get.number.u24
    get.token.value n
    . i=0EF000000hi|n
    go .ok
  .end

  .if name=I.MOVW
    . i=0E3000000h
    go .movwt
  .end
  .if name=I.MOVT
    . i=0E3400000h
    .movwt:
    try verify.cpu ARM.v6T2
    get r=get.register
    fail? r=-1
    try skip.comma
    try get.number.16
    get.token.value n
    . i|(r<<12), x=n&0F000hx<<4
    . i|xc=0FFFhx=n&ci|x
    go .ok
  .end

Note: All code is experimental, beta. I recently discovered this method of testing ARM. LANGUAGE.INC is far from finished.


Description:
Filesize: 75.6 KB
Viewed: 5977 Time(s)

narm.jpg


Post 22 Mar 2014, 10:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.