User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Programming in Basic on Bare Metal Tutorial 1

Fri Jul 20, 2012 10:28 pm

Here is the first of my tutorials on coding in bare metal using a basic like language called DexBasic.
Its more than just a programming language it is also a embedded operating system (DexOS).
The language is really assembly, that is hidden under a basic like language, so you will get all the advantages of assembly like speed and size, but control it by a more user friendly language.
This is just a proof of concept to see if there is any need for such project as this.
The aim of the project is to help people learn low level coding in a more user friendly language, also to help people that want a real time OS for RT application, with out the normal big learning curve.
To that end once my electronic components arrive, i will add some GPIO tuts
Here is a temp site for the project:
http://www.dex-os.com/DexBasic/DexBasic.htm

Tutorial 2 will show how to do this demo:
http://www.youtube.com/watch?v=Hc-5epQT ... el&list=UL
Batteries not included, Some assembly required.

electronstate
Posts: 4
Joined: Mon Jul 16, 2012 8:18 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 1:59 am

interesting tutorial ! is the source code for dexOS available to see how it works with the raspberry pi hardware ?

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 3:08 pm

electronstate wrote:interesting tutorial ! is the source code for dexOS available to see how it works with the raspberry pi hardware ?
The code for the OS will be released, if for example DexBasic is used, but at the moment theres little point, as i have done all the hard work, eg: like set up screen mode so you can out put to screen, this will go for other function too.
Batteries not included, Some assembly required.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 5:46 pm

Yfory wrote:This looks pretty interesting, I'll give it a try and let you know my thoughts. :)
Cool.

This the picture frame code from the youtube video

Code: Select all

include 'DexBasic\DexBasic.inc'

load   BmpImage, ScreenBuffer
sync
goto   MissFirstDelay2screen
Beginning:

load   BmpImage, ScreenBuffer
syncs

MissFirstDelay2screen:
delay  80

load   BmpImage2, ScreenBuffer
syncs
delay  80

load   BmpImage3, ScreenBuffer
syncs
delay  80

load   BmpImage4, ScreenBuffer
syncs
delay  80

load   BmpImage5, ScreenBuffer
syncs
delay  80

load   BmpImage6, ScreenBuffer
syncs
delay  80

goto   Beginning

align 4
BmpImage:
file 'Images\Image1.bmp'
align 4
BmpImage2:
file 'Images\Image2.bmp'
align 4
BmpImage3:
file 'Images\Image3.bmp'
align 4
BmpImage4:
file 'Images\Image4.bmp'
align 4
BmpImage5:
file 'Images\Image5.bmp'
align 4
BmpImage6:
file 'Images\Image6.bmp'
align 4
ProgramSize:
ScreenBuffer:                           
Just add your own images.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 6:23 pm

Nice site - I found the instructions easy to follow, and it did what it said on the tin! Looking forward to tutorial 2...
Ostendo ignarus addo scientia.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 6:52 pm

pygmy_giant wrote:Nice site - I found the instructions easy to follow, and it did what it said on the tin! Looking forward to tutorial 2...
Thanks pygmy_giant, next 2 tutorials will be on using leds and buttons and Uart, as i have them in my electronic parts.
Batteries not included, Some assembly required.

arm
Posts: 5
Joined: Tue Jul 17, 2012 4:59 pm
Location: london, uk.

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 8:43 pm

Hey dude, your website on DexBasic for the raspberry pi is great. Have done similar using Microchip macro commands for the PIC assembler to make a basic/pascal pseudo language. These allow readable code to be produced in assembler so others can read it ! The syntax is not as friendly as DexBasic due to limitations of microchip compiler compared to Fasm. Some examples of commands for ior, xor, add, subtract & multiply 8 bit variables and 'if then condition goto' are shown below:


; algebraic macros functions and, ior, xor, add, subtract, multiply for byte program variables


and_variables MACRO variable1, variable2 ; and 8 bit variable1 to variable2 result in variable2
movf variable1, W
andwf varaiable2, F
ENDM

ior_variables MACRO variable1, variable2 ; ior 8 bit variable1 to variable2 result in variable2
movf variable1, W
iorwf varaiable2, F
ENDM

xor_variables MACRO variable1, variable2 ; xor 8 bit variable1 to variable2 result in variable2
movf variable1, W
xorwf varaiable2, F
ENDM

and_value MACRO variable1, value ; and 8 bit variable1 to literal value
movlw value
andwf variable1, F
ENDM

ior_value MACRO variable1, value ; ior 8 bit variable1 to literal value
movlw value
iorwf variable1, F
ENDM

xor_value MACRO variable1, value ; xor 8 bit variable1 to literal value
movlw value
xorwf variable1, F
ENDM

add_variables MACRO variable1, variable2 ; add 8 bit variable1 to variable2 result in variable2
movf variable1, W ; no overflow check
addwf varaiable2, F
ENDM

multiply_variables MACRO variable1, variable2 ; multiply 8 bit variable1 to variable2 result in variable2
movf variable1, W ; no overflow check
mulwf varaiable2, F
ENDM

subtract_variables MACRO variable1, variable2 ; subtract 8 bit variable1 from variable2 result in variable2
movf variable1, W ; no underflow check
subwf varaiable2, F
ENDM


; macros for program decisions and loops


if_eq_value_goto MACRO prog_var, value, address ; if prog_var equal to literal value then goto address
movf prog_var, W
xorlw value
btfsc STATUS, Z
goto address
ENDM

if_ne_value_goto MACRO prog_var, value, address ; if prog_var not equal to literal value then goto address
movlw value
cpfseq prog_var
goto address
ENDM

if_lt_value_goto MACRO prog_var, value, address ; if prog_var less than literal value then goto address
movlw value
cpfsgt prog_var
goto address
ENDM

if_gt_value_goto MACRO prog_var, value, address ; if prog_var greater than literal value then goto address
movlw value
cpfslt prog_var
goto address
ENDM

if_lt_goto MACRO variable1, variable2, address ; if variable1 less than variable2 then goto address
movf variable2, W
cpfsgt variable1
goto address
ENDM

if_gt_goto MACRO variable1, variable2, address ; if variable1 less than variable2 then goto address
movf variable2, W
cpfslt variable1
goto address
ENDM

if_ne_goto MACRO variable1, variable2, address ; if variable1 less than variable2 then goto address
movf variable2, W
cpfseq variable1
goto address
ENDM

if_eq_goto MACRO variable1, variable2, address ; if variable1 equal to variable2 then goto address
movf variable1, W
xorwf variable2
btfsc STATUS, Z
goto address
ENDM

Please note the above macro code is for the PIC processor not the ARM processor.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Sat Jul 21, 2012 9:17 pm

Hi arm, thanks for your pic examples, i would like to do a pic and avr ver when i have time.
So your examples are very interesting.
There has been some work done in the past to use fasm for pic's.
Batteries not included, Some assembly required.

destruk
Posts: 11
Joined: Thu Jul 19, 2012 3:10 am

Re: Programming in Basic on Bare Metal Tutorial 1

Sun Jul 22, 2012 6:17 am

That is really cool. It's also a better starting point than learning Python (IMO).

gidoca
Posts: 6
Joined: Thu Nov 24, 2011 3:56 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Sun Jul 22, 2012 11:40 am

This looks very cool, I will give it a try. I was thinking of creating a very basic operating system for the RPi myself, just for fun, but I didn't find any documentation about how to set up a basic framebuffer. How did you do that? Is there any documentation about it, other than the source code of the Linux kernel?

gidoca
Posts: 6
Joined: Thu Nov 24, 2011 3:56 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Sun Jul 22, 2012 12:43 pm

Never mind, just found this post of yours that already explains it: http://www.raspberrypi.org/phpBB3/viewt ... 28#p118428

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Sun Jul 22, 2012 6:57 pm

Dex.

I would really, really suggest investing in a spiel chucker, maybe a checker grammar as well, and using it / them religiously on both the text, and any text in your code, before you post anything. You also want to find yourself a proofreader or two. Nobody's gonna tear you to shreds for bad spelling or grammar in forum postings - it's a pretty informal medium - but if you want any tutorials you write to be taken anything like seriously, they need to be properly spelt, have good grammar, and to make sense.
destruk wrote:That is really cool. It's also a better starting point than learning Python (IMO).
I have a few questions regarding DexBasic. As far as I can see, it has no features for doing anything other than rendering text or images to the screen. No variables that I can see, no conditionals (and thus nothing other than infinite looping using goto), no arithmetic expressions and certainly no mention of any sort of expression ordering, no composition, nothing that would actually make it into any sort of useful language. I was hoping that this was merely a failure on Craig's part to document any of this (after all, the site does say "More commands to come"), but the current incarnation of the include file doesn't indicate that this is the case.

It' a decent example of the sort of things you can do (and, conversely, when you start looking under the hood, the things you can't do) when you abuse an assembler's macro system. As a programming language, it's far from being a competitor for Python as it stands, and nor will it ever be, due to the aforementioned shortcomings of attempting to build a turing complete language using a macro preprocessor alone.

Yeah, that sounds negative. Sorry 'bout that.

Simon

destruk
Posts: 11
Joined: Thu Jul 19, 2012 3:10 am

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 1:44 am

What I meant was, to simply turn the raspberry pi on and make it do some 'work' that is meaningful to create something, this is great. I bet it even boots faster than the default OS. Eventually I'm sure all the other required commands would be added, it's not going to be initially used to create cutting edge commercial 3D games on the raspberry pi, but it's a fairly decent start. For my own project I have in mind, it'd have a menu system, display some parsed xml content lists, and play music and videos in a compact form factor with instant-on boot time over HDMI for audio/video - that doesn't require 80% of what you said this doesn't have. :)

If you are the kind of person who takes a programming book and reads it through cover to cover to see everything it does and learn how it all works at one go, then this can be less than satisfactory - but if you're a person who takes a single command and explores all the practical applications of that command before moving onto the next one then this could be the way to go.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 6:59 am

destruk wrote:What I meant was, to simply turn the raspberry pi on and make it do some 'work' that is meaningful to create something, this is great. I bet it even boots faster than the default OS.
The end result boots very fast. 2 seconds or thereabouts. That's understandable, because it's doing next to nothing at the moment (LambdaPi boots to a lisp command prompt over serial in a comparable time[1]). However, the actual creation part of Dex's approach requires an external PC (Windows or, possibly, Linux)[2]. You're not going to be actually programming on the Pi any time soon. That's important for the Pi's goals, but not necessarily Dex's.
destruk wrote:For my own project I have in mind, it'd have a menu system, display some parsed xml content lists, and play music and videos in a compact form factor with instant-on boot time over HDMI for audio/video - that doesn't require 80% of what you said this doesn't have. :)
No? You don't think you need expressions, conditional looping, and all that other impenetrable "programming language" jazz to read and parse XML? Here's a hint. You do[3], and much more besides.

Simon

[1] Although not in the currently public form, I'm testing for horrible showstoppers at the moment.
[2] I also require an external machine; due to not having USB up and running yet, I'm tethered to a serial console.
[3] You need on-device filesystem access, too, unless you're going to be recompiling every time you actually want to change (for example) the videos you want to play, but I'm sure Dex will have that up pretty soon. Probably sooner than I will, to be honest.

ginkgo
Posts: 1
Joined: Fri Jul 20, 2012 2:14 pm

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 11:06 am

Hi Dex,
cool site on DexBasic. good use of assembler macros to produce a useful language for fast deterministic real time programming. by using macros its easy for users to see how the commands work so they can be modified, enhanced and reused. cant wait to see this project grow and grow !!

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 11:30 am

tufty wrote:Dex.

I would really, really suggest investing in a spiel chucker, maybe a checker grammar as well, and using it / them religiously on both the text, and any text in your code, before you post anything. You also want to find yourself a proofreader or two. Nobody's gonna tear you to shreds for bad spelling or grammar in forum postings - it's a pretty informal medium - but if you want any tutorials you write to be taken anything like seriously, they need to be properly spelt, have good grammar, and to make sense.
I will hold my hands up here, my spelling and grammar is not very good.
tufty wrote:I have a few questions regarding DexBasic. As far as I can see, it has no features for doing anything other than rendering text or images to the screen. No variables that I can see, no conditionals (and thus nothing other than infinite looping using goto), no arithmetic expressions and certainly no mention of any sort of expression ordering, no composition, nothing that would actually make it into any sort of useful language. I was hoping that this was merely a failure on Craig's part to document any of this (after all, the site does say "More commands to come"), but the current incarnation of the include file doesn't indicate that this is the case.

It' a decent example of the sort of things you can do (and, conversely, when you start looking under the hood, the things you can't do) when you abuse an assembler's macro system. As a programming language, it's far from being a competitor for Python as it stands, and nor will it ever be, due to the aforementioned shortcomings of attempting to build a turing complete language using a macro preprocessor alone.

Yeah, that sounds negative. Sorry 'bout that.

Simon
Here i think you underestimate the power of fasm macros.
Built into fasm is some HLL functions
You can for example without macros do this

Code: Select all

 if count & ~ count mod 4
        mov cx,count/4
        rep movsd
    else if count>4
        mov cx,count/4
        rep movsd
        mov cx,count mod 4
        rep movsb
    else
        mov cx,count
        rep movsb
    end if

Or this

Code: Select all

  s = x/2
    while x/s <> s
        s = (s+x/s)/2
        if % = 100
            break
        end if
    end while
Here is a example "Rijndael (and AES) macros for fasm"
Both Encryption/decryption.

Code: Select all

macro   rijndael_fasm_init key_size,block_size
{ if (key_size mod 32) | (key_size<128) | (key_size>256)
        halt - Bad key size
  else if (block_size mod 32) | (block_size<128) | (block_size>256)
        halt - Bad block size
  end if
        rijndael_fasm_blocks=block_size/32
        rijndael_fasm_keys=key_size/32
  if block_size>key_size
        rijndael_fasm_rounds=block_size/32+6
  else
        rijndael_fasm_rounds=key_size/32+6
  end if
        rijndael_fasm_shift1=1
  if rijndael_fasm_blocks <= 7
        rijndael_fasm_shift2=2  
  else
        rijndael_fasm_shift2=3
  end if
  if rijndael_fasm_blocks <= 6
        rijndael_fasm_shift3=3
  else
        rijndael_fasm_shift3=4
  end if
}

macro   rijndael_fasm_s_box the_byte
{       virtual at 0
        db      063h,07Ch,077h,07Bh,0F2h,06Bh,06Fh,0C5h,030h,001h,067h,02Bh,0FEh,0D7h,0ABh,076h
        db      0CAh,082h,0C9h,07Dh,0FAh,059h,047h,0F0h,0ADh,0D4h,0A2h,0AFh,09Ch,0A4h,072h,0C0h
        db      0B7h,0FDh,093h,026h,036h,03Fh,0F7h,0CCh,034h,0A5h,0E5h,0F1h,071h,0D8h,031h,015h
        db      004h,0C7h,023h,0C3h,018h,096h,005h,09Ah,007h,012h,080h,0E2h,0EBh,027h,0B2h,075h
        db      009h,083h,02Ch,01Ah,01Bh,06Eh,05Ah,0A0h,052h,03Bh,0D6h,0B3h,029h,0E3h,02Fh,084h
        db      053h,0D1h,000h,0EDh,020h,0FCh,0B1h,05Bh,06Ah,0CBh,0BEh,039h,04Ah,04Ch,058h,0CFh
        db      0D0h,0EFh,0AAh,0FBh,043h,04Dh,033h,085h,045h,0F9h,002h,07Fh,050h,03Ch,09Fh,0A8h
        db      051h,0A3h,040h,08Fh,092h,09Dh,038h,0F5h,0BCh,0B6h,0DAh,021h,010h,0FFh,0F3h,0D2h
        db      0CDh,00Ch,013h,0ECh,05Fh,097h,044h,017h,0C4h,0A7h,07Eh,03Dh,064h,05Dh,019h,073h
        db      060h,081h,04Fh,0DCh,022h,02Ah,090h,088h,046h,0EEh,0B8h,014h,0DEh,05Eh,00Bh,0DBh
        db      0E0h,032h,03Ah,00Ah,049h,006h,024h,05Ch,0C2h,0D3h,0ACh,062h,091h,095h,0E4h,079h
        db      0E7h,0C8h,037h,06Dh,08Dh,0D5h,04Eh,0A9h,06Ch,056h,0F4h,0EAh,065h,07Ah,0AEh,008h
        db      0BAh,078h,025h,02Eh,01Ch,0A6h,0B4h,0C6h,0E8h,0DDh,074h,01Fh,04Bh,0BDh,08Bh,08Ah
        db      070h,03Eh,0B5h,066h,048h,003h,0F6h,00Eh,061h,035h,057h,0B9h,086h,0C1h,01Dh,09Eh
        db      0E1h,0F8h,098h,011h,069h,0D9h,08Eh,094h,09Bh,01Eh,087h,0E9h,0CEh,055h,028h,0DFh
        db      08Ch,0A1h,089h,00Dh,0BFh,0E6h,042h,068h,041h,099h,02Dh,00Fh,0B0h,054h,0BBh,016h
        load    rijndael_fasm_s_box_result byte from the_byte
        end virtual
}

macro   rijndael_fasm_si_box the_byte
{       virtual at 0
        db      052h,009h,06Ah,0D5h,030h,036h,0A5h,038h,0BFh,040h,0A3h,09Eh,081h,0F3h,0D7h,0FBh
        db      07Ch,0E3h,039h,082h,09Bh,02Fh,0FFh,087h,034h,08Eh,043h,044h,0C4h,0DEh,0E9h,0CBh
        db      054h,07Bh,094h,032h,0A6h,0C2h,023h,03Dh,0EEh,04Ch,095h,00Bh,042h,0FAh,0C3h,04Eh
        db      008h,02Eh,0A1h,066h,028h,0D9h,024h,0B2h,076h,05Bh,0A2h,049h,06Dh,08Bh,0D1h,025h
        db      072h,0F8h,0F6h,064h,086h,068h,098h,016h,0D4h,0A4h,05Ch,0CCh,05Dh,065h,0B6h,092h
        db      06Ch,070h,048h,050h,0FDh,0EDh,0B9h,0DAh,05Eh,015h,046h,057h,0A7h,08Dh,09Dh,084h
        db      090h,0D8h,0ABh,000h,08Ch,0BCh,0D3h,00Ah,0F7h,0E4h,058h,005h,0B8h,0B3h,045h,006h
        db      0D0h,02Ch,01Eh,08Fh,0CAh,03Fh,00Fh,002h,0C1h,0AFh,0BDh,003h,001h,013h,08Ah,06Bh
        db      03Ah,091h,011h,041h,04Fh,067h,0DCh,0EAh,097h,0F2h,0CFh,0CEh,0F0h,0B4h,0E6h,073h
        db      096h,0ACh,074h,022h,0E7h,0ADh,035h,085h,0E2h,0F9h,037h,0E8h,01Ch,075h,0DFh,06Eh
        db      047h,0F1h,01Ah,071h,01Dh,029h,0C5h,089h,06Fh,0B7h,062h,00Eh,0AAh,018h,0BEh,01Bh
        db      0FCh,056h,03Eh,04Bh,0C6h,0D2h,079h,020h,09Ah,0DBh,0C0h,0FEh,078h,0CDh,05Ah,0F4h
        db      01Fh,0DDh,0A8h,033h,088h,007h,0C7h,031h,0B1h,012h,010h,059h,027h,080h,0ECh,05Fh
        db      060h,051h,07Fh,0A9h,019h,0B5h,04Ah,00Dh,02Dh,0E5h,07Ah,09Fh,093h,0C9h,09Ch,0EFh
        db      0A0h,0E0h,03Bh,04Dh,0AEh,02Ah,0F5h,0B0h,0C8h,0EBh,0BBh,03Ch,083h,053h,099h,061h
        db      017h,02Bh,004h,07Eh,0BAh,077h,0D6h,026h,0E1h,069h,014h,063h,055h,021h,00Ch,07Dh
        load    rijndael_fasm_si_box_result byte from the_byte
        end virtual
}

macro   rijndael_fasm_te the_dword
{       virtual at 0
        dd      0A56363C6h,0847C7CF8h,0997777EEh,08D7B7BF6h,00DF2F2FFh,0BD6B6BD6h,0B16F6FDEh,054C5C591h
        dd      050303060h,003010102h,0A96767CEh,07D2B2B56h,019FEFEE7h,062D7D7B5h,0E6ABAB4Dh,09A7676ECh
        dd      045CACA8Fh,09D82821Fh,040C9C989h,0877D7DFAh,015FAFAEFh,0EB5959B2h,0C947478Eh,00BF0F0FBh
        dd      0ECADAD41h,067D4D4B3h,0FDA2A25Fh,0EAAFAF45h,0BF9C9C23h,0F7A4A453h,0967272E4h,05BC0C09Bh
        dd      0C2B7B775h,01CFDFDE1h,0AE93933Dh,06A26264Ch,05A36366Ch,0413F3F7Eh,002F7F7F5h,04FCCCC83h
        dd      05C343468h,0F4A5A551h,034E5E5D1h,008F1F1F9h,0937171E2h,073D8D8ABh,053313162h,03F15152Ah
        dd      00C040408h,052C7C795h,065232346h,05EC3C39Dh,028181830h,0A1969637h,00F05050Ah,0B59A9A2Fh
        dd      00907070Eh,036121224h,09B80801Bh,03DE2E2DFh,026EBEBCDh,06927274Eh,0CDB2B27Fh,09F7575EAh
        dd      01B090912h,09E83831Dh,0742C2C58h,02E1A1A34h,02D1B1B36h,0B26E6EDCh,0EE5A5AB4h,0FBA0A05Bh
        dd      0F65252A4h,04D3B3B76h,061D6D6B7h,0CEB3B37Dh,07B292952h,03EE3E3DDh,0712F2F5Eh,097848413h
        dd      0F55353A6h,068D1D1B9h,000000000h,02CEDEDC1h,060202040h,01FFCFCE3h,0C8B1B179h,0ED5B5BB6h
        dd      0BE6A6AD4h,046CBCB8Dh,0D9BEBE67h,04B393972h,0DE4A4A94h,0D44C4C98h,0E85858B0h,04ACFCF85h
        dd      06BD0D0BBh,02AEFEFC5h,0E5AAAA4Fh,016FBFBEDh,0C5434386h,0D74D4D9Ah,055333366h,094858511h
        dd      0CF45458Ah,010F9F9E9h,006020204h,0817F7FFEh,0F05050A0h,0443C3C78h,0BA9F9F25h,0E3A8A84Bh
        dd      0F35151A2h,0FEA3A35Dh,0C0404080h,08A8F8F05h,0AD92923Fh,0BC9D9D21h,048383870h,004F5F5F1h
        dd      0DFBCBC63h,0C1B6B677h,075DADAAFh,063212142h,030101020h,01AFFFFE5h,00EF3F3FDh,06DD2D2BFh
        dd      04CCDCD81h,0140C0C18h,035131326h,02FECECC3h,0E15F5FBEh,0A2979735h,0CC444488h,03917172Eh
        dd      057C4C493h,0F2A7A755h,0827E7EFCh,0473D3D7Ah,0AC6464C8h,0E75D5DBAh,02B191932h,0957373E6h
        dd      0A06060C0h,098818119h,0D14F4F9Eh,07FDCDCA3h,066222244h,07E2A2A54h,0AB90903Bh,08388880Bh
        dd      0CA46468Ch,029EEEEC7h,0D3B8B86Bh,03C141428h,079DEDEA7h,0E25E5EBCh,01D0B0B16h,076DBDBADh
        dd      03BE0E0DBh,056323264h,04E3A3A74h,01E0A0A14h,0DB494992h,00A06060Ch,06C242448h,0E45C5CB8h
        dd      05DC2C29Fh,06ED3D3BDh,0EFACAC43h,0A66262C4h,0A8919139h,0A4959531h,037E4E4D3h,08B7979F2h
        dd      032E7E7D5h,043C8C88Bh,05937376Eh,0B76D6DDAh,08C8D8D01h,064D5D5B1h,0D24E4E9Ch,0E0A9A949h
        dd      0B46C6CD8h,0FA5656ACh,007F4F4F3h,025EAEACFh,0AF6565CAh,08E7A7AF4h,0E9AEAE47h,018080810h
        dd      0D5BABA6Fh,0887878F0h,06F25254Ah,0722E2E5Ch,0241C1C38h,0F1A6A657h,0C7B4B473h,051C6C697h
        dd      023E8E8CBh,07CDDDDA1h,09C7474E8h,0211F1F3Eh,0DD4B4B96h,0DCBDBD61h,0868B8B0Dh,0858A8A0Fh
        dd      0907070E0h,0423E3E7Ch,0C4B5B571h,0AA6666CCh,0D8484890h,005030306h,001F6F6F7h,0120E0E1Ch
        dd      0A36161C2h,05F35356Ah,0F95757AEh,0D0B9B969h,091868617h,058C1C199h,0271D1D3Ah,0B99E9E27h
        dd      038E1E1D9h,013F8F8EBh,0B398982Bh,033111122h,0BB6969D2h,070D9D9A9h,0898E8E07h,0A7949433h
        dd      0B69B9B2Dh,0221E1E3Ch,092878715h,020E9E9C9h,049CECE87h,0FF5555AAh,078282850h,07ADFDFA5h
        dd      08F8C8C03h,0F8A1A159h,080898909h,0170D0D1Ah,0DABFBF65h,031E6E6D7h,0C6424284h,0B86868D0h
        dd      0C3414182h,0B0999929h,0772D2D5Ah,0110F0F1Eh,0CBB0B07Bh,0FC5454A8h,0D6BBBB6Dh,03A16162Ch
        load    rijndael_fasm_te_result dword from (the_dword)*4
        end virtual
}

macro   rijndael_fasm_td the_dword
{       virtual at 0
        dd      050A7F451h,05365417Eh,0C3A4171Ah,0965E273Ah,0CB6BAB3Bh,0F1459D1Fh,0AB58FAACh,09303E34Bh
        dd      055FA3020h,0F66D76ADh,09176CC88h,0254C02F5h,0FCD7E54Fh,0D7CB2AC5h,080443526h,08FA362B5h
        dd      0495AB1DEh,0671BBA25h,0980EEA45h,0E1C0FE5Dh,002752FC3h,012F04C81h,0A397468Dh,0C6F9D36Bh
        dd      0E75F8F03h,0959C9215h,0EB7A6DBFh,0DA595295h,02D83BED4h,0D3217458h,02969E049h,044C8C98Eh
        dd      06A89C275h,078798EF4h,06B3E5899h,0DD71B927h,0B64FE1BEh,017AD88F0h,066AC20C9h,0B43ACE7Dh
        dd      0184ADF63h,082311AE5h,060335197h,0457F5362h,0E07764B1h,084AE6BBBh,01CA081FEh,0942B08F9h
        dd      058684870h,019FD458Fh,0876CDE94h,0B7F87B52h,023D373ABh,0E2024B72h,0578F1FE3h,02AAB5566h
        dd      00728EBB2h,003C2B52Fh,09A7BC586h,0A50837D3h,0F2872830h,0B2A5BF23h,0BA6A0302h,05C8216EDh
        dd      02B1CCF8Ah,092B479A7h,0F0F207F3h,0A1E2694Eh,0CDF4DA65h,0D5BE0506h,01F6234D1h,08AFEA6C4h
        dd      09D532E34h,0A055F3A2h,032E18A05h,075EBF6A4h,039EC830Bh,0AAEF6040h,0069F715Eh,051106EBDh
        dd      0F98A213Eh,03D06DD96h,0AE053EDDh,046BDE64Dh,0B58D5491h,0055DC471h,06FD40604h,0FF155060h
        dd      024FB9819h,097E9BDD6h,0CC434089h,0779ED967h,0BD42E8B0h,0888B8907h,0385B19E7h,0DBEEC879h
        dd      0470A7CA1h,0E90F427Ch,0C91E84F8h,000000000h,083868009h,048ED2B32h,0AC70111Eh,04E725A6Ch
        dd      0FBFF0EFDh,05638850Fh,01ED5AE3Dh,027392D36h,064D90F0Ah,021A65C68h,0D1545B9Bh,03A2E3624h
        dd      0B1670A0Ch,00FE75793h,0D296EEB4h,09E919B1Bh,04FC5C080h,0A220DC61h,0694B775Ah,0161A121Ch
        dd      00ABA93E2h,0E52AA0C0h,043E0223Ch,01D171B12h,00B0D090Eh,0ADC78BF2h,0B9A8B62Dh,0C8A91E14h
        dd      08519F157h,04C0775AFh,0BBDD99EEh,0FD607FA3h,09F2601F7h,0BCF5725Ch,0C53B6644h,0347EFB5Bh
        dd      07629438Bh,0DCC623CBh,068FCEDB6h,063F1E4B8h,0CADC31D7h,010856342h,040229713h,02011C684h
        dd      07D244A85h,0F83DBBD2h,01132F9AEh,06DA129C7h,04B2F9E1Dh,0F330B2DCh,0EC52860Dh,0D0E3C177h
        dd      06C16B32Bh,099B970A9h,0FA489411h,02264E947h,0C48CFCA8h,01A3FF0A0h,0D82C7D56h,0EF903322h
        dd      0C74E4987h,0C1D138D9h,0FEA2CA8Ch,0360BD498h,0CF81F5A6h,028DE7AA5h,0268EB7DAh,0A4BFAD3Fh
        dd      0E49D3A2Ch,00D927850h,09BCC5F6Ah,062467E54h,0C2138DF6h,0E8B8D890h,05EF7392Eh,0F5AFC382h
        dd      0BE805D9Fh,07C93D069h,0A92DD56Fh,0B31225CFh,03B99ACC8h,0A77D1810h,06E639CE8h,07BBB3BDBh
        dd      0097826CDh,0F418596Eh,001B79AECh,0A89A4F83h,0656E95E6h,07EE6FFAAh,008CFBC21h,0E6E815EFh
        dd      0D99BE7BAh,0CE366F4Ah,0D4099FEAh,0D67CB029h,0AFB2A431h,031233F2Ah,03094A5C6h,0C066A235h
        dd      037BC4E74h,0A6CA82FCh,0B0D090E0h,015D8A733h,04A9804F1h,0F7DAEC41h,00E50CD7Fh,02FF69117h
        dd      08DD64D76h,04DB0EF43h,0544DAACCh,0DF0496E4h,0E3B5D19Eh,01B886A4Ch,0B81F2CC1h,07F516546h
        dd      004EA5E9Dh,05D358C01h,0737487FAh,02E410BFBh,05A1D67B3h,052D2DB92h,0335610E9h,01347D66Dh
        dd      08C61D79Ah,07A0CA137h,08E14F859h,0893C13EBh,0EE27A9CEh,035C961B7h,0EDE51CE1h,03CB1477Ah
        dd      059DFD29Ch,03F73F255h,079CE1418h,0BF37C773h,0EACDF753h,05BAAFD5Fh,0146F3DDFh,086DB4478h
        dd      081F3AFCAh,03EC468B9h,02C342438h,05F40A3C2h,072C31D16h,00C25E2BCh,08B493C28h,041950DFFh
        dd      07101A839h,0DEB30C08h,09CE4B4D8h,090C15664h,06184CB7Bh,070B632D5h,0745C6C48h,04257B8D0h
        load    rijndael_fasm_td_result dword from (the_dword)*4
        end virtual
}

macro   rijndael_fasm_rcon the_byte
{       virtual at 0
        db      001h,002h,004h,008h,010h,020h,040h,080h,01Bh,036h,06Ch,0D8h,0ABh,04Dh,09Ah,02Fh
        db      05Eh,0BCh,063h,0C6h,097h,035h,06Ah,0D4h,0B3h,07Dh,0FAh,0EFh,0C5h,091h
        load    rijndael_fasm_rcon_result byte from the_byte
        end virtual
}

macro   rijndael_fasm_shifts_e the_byte
{       virtual at 0
        repeat rijndael_fasm_blocks
        db      (%-1)
        db      (%-1+rijndael_fasm_shift1) mod rijndael_fasm_blocks
        db      (%-1+rijndael_fasm_shift2) mod rijndael_fasm_blocks
        db      (%-1+rijndael_fasm_shift3) mod rijndael_fasm_blocks
        end repeat
        load    rijndael_fasm_shifts_e_result byte from the_byte
        end virtual
}

macro   rijndael_fasm_shifts_d the_byte
{       virtual at 0
        repeat rijndael_fasm_blocks
        db      (%-1)
        db      (%-1+rijndael_fasm_blocks-rijndael_fasm_shift1) mod rijndael_fasm_blocks
        db      (%-1+rijndael_fasm_blocks-rijndael_fasm_shift2) mod rijndael_fasm_blocks
        db      (%-1+rijndael_fasm_blocks-rijndael_fasm_shift3) mod rijndael_fasm_blocks
        end repeat
        load    rijndael_fasm_shifts_d_result byte from the_byte
        end virtual
}

macro   ror_dword_8 variable {variable=(variable shr 8) or ((variable and 0ffh) shl 24)}

macro   rijndael_fasm_key_schedule [keys]
{ common
  virtual at 0
    if ~ keys eq
        dd keys
    end if
        rq 60
  repeat rijndael_fasm_blocks*(rijndael_fasm_rounds+1)-rijndael_fasm_keys
    load rijndael_fasm_temp dword from (rijndael_fasm_keys+%-1)*4-4
    if ((rijndael_fasm_keys>6)&(((%-1) mod rijndael_fasm_keys) and 3)=0)|\
        ((rijndael_fasm_keys<=6)&((%-1) mod rijndael_fasm_keys)=0)
        rijndael_fasm_s_box (rijndael_fasm_temp and 0ffh)
        rijndael_fasm_temp2=rijndael_fasm_s_box_result
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 8) and 0ffh)
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 8)
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 16) and 0ffh)
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 16)
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 24) and 0ffh)
        rijndael_fasm_temp=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 24)
      if ((%-1) mod rijndael_fasm_keys)=0
        ror_dword_8 rijndael_fasm_temp
        rijndael_fasm_rcon (%-1)/rijndael_fasm_keys
        rijndael_fasm_temp=rijndael_fasm_temp xor rijndael_fasm_rcon_result
      end if
    end if
    load rijndael_fasm_temp2 dword from (%-1)*4
    rijndael_fasm_temp=rijndael_fasm_temp xor rijndael_fasm_temp2
    store dword rijndael_fasm_temp at (rijndael_fasm_keys+%-1)*4
  end repeat
  rept 60 rept_loop:0 \{ load rijndael_fasm_rk_e_\#rept_loop qword from rept_loop*8 \}
  repeat rijndael_fasm_blocks*(rijndael_fasm_rounds-1)
        load rijndael_fasm_temp dword from (rijndael_fasm_blocks+%-1)*4
        rijndael_fasm_s_box (rijndael_fasm_temp and 0ffh)
        rijndael_fasm_td rijndael_fasm_s_box_result
        rijndael_fasm_temp2=rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 8) and 0ffh)
        rijndael_fasm_td rijndael_fasm_s_box_result
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 16) and 0ffh)
        rijndael_fasm_td rijndael_fasm_s_box_result
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_s_box ((rijndael_fasm_temp shr 24) and 0ffh)
        rijndael_fasm_td rijndael_fasm_s_box_result
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp
        store dword rijndael_fasm_temp at (rijndael_fasm_blocks+%-1)*4
  end repeat
  rept 60 rept_loop:0 \{ load rijndael_fasm_rk_d_\#rept_loop qword from rept_loop*8 \}
  end virtual
}

macro   rijndael_fasm_encrypt_block block_address
{       local ..src,..key,..dst
        rept 8 rept_loop:0 \{ load rijndael_fasm_block_\#rept_loop dword from block_address+(rept_loop mod rijndael_fasm_blocks)*4 \}
  virtual at 0
..src=$
        rept 8 rept_loop:0 \{dd rijndael_fasm_block_\#rept_loop\}
..key=$
        rept 60 rept_loop:0 \{dq rijndael_fasm_rk_e_\#rept_loop\}
..dst=$
        rd 8
    repeat rijndael_fasm_blocks
        load    rijndael_fasm_temp dword from ..src+(%-1)*4
        load    rijndael_fasm_temp2 dword from ..key+(%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..src+(%-1)*4
    end repeat
    repeat (rijndael_fasm_rounds-1)
        rijndael_fasm_round=%
      repeat rijndael_fasm_blocks
        rijndael_fasm_shifts_e (%-1)*4+0
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+0
        rijndael_fasm_te rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_te_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_e (%-1)*4+1
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+1
        rijndael_fasm_te rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_te_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_e (%-1)*4+2
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+2
        rijndael_fasm_te rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_te_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_e (%-1)*4+3
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+3
        rijndael_fasm_te rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_te_result
        ror_dword_8 rijndael_fasm_temp2
        load    rijndael_fasm_temp dword from ..key+(rijndael_fasm_round*rijndael_fasm_blocks+%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..dst+(%-1)*4
      end repeat
      repeat 4
        load    rijndael_fasm_temp qword from ..dst+(%-1)*8
        store   qword rijndael_fasm_temp at ..src+(%-1)*8
      end repeat
    end repeat
    repeat rijndael_fasm_blocks
        rijndael_fasm_shifts_e (%-1)*4+0
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+0
        rijndael_fasm_s_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_s_box_result
        rijndael_fasm_shifts_e (%-1)*4+1
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+1
        rijndael_fasm_s_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 8)
        rijndael_fasm_shifts_e (%-1)*4+2
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+2
        rijndael_fasm_s_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 16)
        rijndael_fasm_shifts_e (%-1)*4+3
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_e_result*4+3
        rijndael_fasm_s_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_s_box_result shl 24)
        load    rijndael_fasm_temp dword from ..key+(rijndael_fasm_rounds*rijndael_fasm_blocks+%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..dst+(%-1)*4
    end repeat
        rept 8 rept_loop:0 \{ load rijndael_fasm_block_\#rept_loop dword from ..dst+rept_loop*4 \}
  end virtual
        rept 8 rept_loop:0 \{   if rept_loop<rijndael_fasm_blocks
                                    store dword rijndael_fasm_block_\#rept_loop at block_address+rept_loop*4
                                end if
                                \}
}

macro   rijndael_fasm_decrypt_block block_address
{       local ..src,..key,..dst
        rept 8 rept_loop:0 \{ load rijndael_fasm_block_\#rept_loop dword from block_address+(rept_loop mod rijndael_fasm_blocks)*4 \}
  virtual at 0
..src=$
        rept 8 rept_loop:0 \{dd rijndael_fasm_block_\#rept_loop\}
..key=$
        rept 60 rept_loop:0 \{dq rijndael_fasm_rk_d_\#rept_loop\}
..dst=$
        rd 8
    repeat rijndael_fasm_blocks
        load    rijndael_fasm_temp dword from ..src+(%-1)*4
        load    rijndael_fasm_temp2 dword from ..key+(rijndael_fasm_rounds*rijndael_fasm_blocks+%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..src+(%-1)*4
    end repeat
    repeat (rijndael_fasm_rounds-1)
        rijndael_fasm_round=rijndael_fasm_rounds-%
      repeat rijndael_fasm_blocks
        rijndael_fasm_shifts_d (%-1)*4+0
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+0
        rijndael_fasm_td rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_d (%-1)*4+1
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+1
        rijndael_fasm_td rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_d (%-1)*4+2
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+2
        rijndael_fasm_td rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        rijndael_fasm_shifts_d (%-1)*4+3
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+3
        rijndael_fasm_td rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2 xor rijndael_fasm_td_result
        ror_dword_8 rijndael_fasm_temp2
        load    rijndael_fasm_temp dword from ..key+(rijndael_fasm_round*rijndael_fasm_blocks+%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..dst+(%-1)*4
      end repeat
      repeat 4
        load    rijndael_fasm_temp qword from ..dst+(%-1)*8
        store   qword rijndael_fasm_temp at ..src+(%-1)*8
      end repeat
    end repeat
    repeat rijndael_fasm_blocks
        rijndael_fasm_shifts_d (%-1)*4+0
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+0
        rijndael_fasm_si_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_si_box_result
        rijndael_fasm_shifts_d (%-1)*4+1
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+1
        rijndael_fasm_si_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_si_box_result shl 8)
        rijndael_fasm_shifts_d (%-1)*4+2
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+2
        rijndael_fasm_si_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_si_box_result shl 16)
        rijndael_fasm_shifts_d (%-1)*4+3
        load    rijndael_fasm_temp byte from ..src+rijndael_fasm_shifts_d_result*4+3
        rijndael_fasm_si_box rijndael_fasm_temp
        rijndael_fasm_temp2=rijndael_fasm_temp2+(rijndael_fasm_si_box_result shl 24)
        load    rijndael_fasm_temp dword from ..key+(%-1)*4
        rijndael_fasm_temp=rijndael_fasm_temp2 xor rijndael_fasm_temp
        store   dword rijndael_fasm_temp at ..dst+(%-1)*4
    end repeat
        rept 8 rept_loop:0 \{ load rijndael_fasm_block_\#rept_loop dword from ..dst+rept_loop*4 \}
  end virtual
        rept 8 rept_loop:0 \{   if rept_loop<rijndael_fasm_blocks
                                    store dword rijndael_fasm_block_\#rept_loop at block_address+rept_loop*4
                                end if
                                \}
}

macro   rijndael_fasm_encrypt_blocks_ecb block_address,bytes
{       repeat (bytes-1)/(rijndael_fasm_blocks*4)+1
          rijndael_fasm_encrypt_block block_address+(%-1)*rijndael_fasm_blocks*4
        end repeat
}

macro   rijndael_fasm_decrypt_blocks_ecb block_address,bytes
{       repeat (bytes-1)/(rijndael_fasm_blocks*4)+1
          rijndael_fasm_decrypt_block block_address+(%-1)*rijndael_fasm_blocks*4
        end repeat
}

macro   rijndael_fasm_encrypt_blocks_cbc block_address,bytes,[iv]
{       common
  virtual at 0
    if ~ iv eq
        dd iv
    end if
        dd 8 dup (0)
        rept 8 rept_loop:0 \{ load rijndael_fasm_iv_\#rept_loop dword from rept_loop*4 \}
  end virtual
        repeat (bytes-1)/(rijndael_fasm_blocks*4)+1
          rijndael_fasm_cbc=block_address+(%-1)*rijndael_fasm_blocks*4
          rept 8 rept_loop:0 \{ if rept_loop<rijndael_fasm_blocks
                                    load rijndael_fasm_temp dword from rijndael_fasm_cbc+rept_loop*4
                                    rijndael_fasm_temp=rijndael_fasm_temp xor rijndael_fasm_iv_\#rept_loop
                                    store dword rijndael_fasm_temp at rijndael_fasm_cbc+rept_loop*4
                                end if
                                \}
          rijndael_fasm_encrypt_block rijndael_fasm_cbc
          rept 8 rept_loop:0 \{ load rijndael_fasm_iv_\#rept_loop dword from rijndael_fasm_cbc+(rept_loop mod rijndael_fasm_blocks)*4 \}
        end repeat
}

macro   rijndael_fasm_decrypt_blocks_cbc block_address,bytes,[iv]
{       common
  virtual at 0
    if ~ iv eq
        dd iv
    end if
        dd 8 dup (0)
        rept 8 rept_loop:0 \{ load rijndael_fasm_iv_new_\#rept_loop dword from rept_loop*4 \}
  end virtual
        repeat (bytes-1)/(rijndael_fasm_blocks*4)+1
          rijndael_fasm_cbc=block_address+(%-1)*rijndael_fasm_blocks*4
          rept 8 rept_loop:0 \{ load rijndael_fasm_iv_last_\#rept_loop dword from rijndael_fasm_cbc+(rept_loop mod rijndael_fasm_blocks)*4 \}
          rijndael_fasm_decrypt_block rijndael_fasm_cbc
          rept 8 rept_loop:0 \{ if rept_loop<rijndael_fasm_blocks
                                    load rijndael_fasm_temp dword from rijndael_fasm_cbc+rept_loop*4
                                    rijndael_fasm_temp=rijndael_fasm_temp xor rijndael_fasm_iv_new_\#rept_loop
                                    store dword rijndael_fasm_temp at rijndael_fasm_cbc+rept_loop*4
                                end if
                                \}
          rept 8 rept_loop:0 \{ rijndael_fasm_iv_new_\#rept_loop=rijndael_fasm_iv_last_\#rept_loop \}
        end repeat
}
                                                      
Note: i have only use simple examples so as not to scare beginners away.

Anything you can do in basic, would be easy possible using this method.
DexBasic language will grow to be has fully featured as any other basic.
But i may use some parts of assembly instead, if they are more powerful and just as easy to understand.

I may even add a DexBasic interpreter if needed.

Also i am not sure there is a need for a bare metal OS that let's you program on the PI its self, linux is good for that.
I am looking to make (and i think theres more a need) for using the R-PI to be a more powerful arduino, that runs one program in real-time, eg: robots.
Batteries not included, Some assembly required.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 11:36 am

ginkgo wrote:Hi Dex,
cool site on DexBasic. good use of assembler macros to produce a useful language for fast deterministic real time programming. by using macros its easy for users to see how the commands work so they can be modified, enhanced and reused. cant wait to see this project grow and grow !!
Thanks ginkgo and everyone else thats posted, one-thing you can be sure of, is when i set myself a goal, i always for fill it.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 5:50 pm

'for fill it' - thats a joke right? (cf speil chucker)

My spelling and grammar may be bad, but my assembler is non-existent, so you'll also have to stupid-proof the tutorials for HL noobs like me...
Ostendo ignarus addo scientia.

destruk
Posts: 11
Joined: Thu Jul 19, 2012 3:10 am

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 10:03 pm

Obviously Tuffy, you don't need anything else to program. If the program uses a single command "Print Hello" - and the only command the system supports is Print, then that is all you need. Would the slideshow work if you needed arithmetic operations or the other features you speak of? No. I think you're just upset that someone else is trying to do something and they succeeded, where you have failed. It's understandable you feel that way. It depends on what you want to create - if what you want to make just simply can't be done without a specific feature, then you need that feature, or you need to create it. That's the point isn't it, to learn, to better yourself? To be a happier person? Hopefully you can comprehend this. Sorry for the tangent - looking forward to tutorial 2.

bobc
Posts: 86
Joined: Fri Apr 06, 2012 8:01 am

Re: Programming in Basic on Bare Metal Tutorial 1

Mon Jul 23, 2012 10:54 pm

Well, I suppose macro assembly is a small step forward from regular assembly.

If assembly is "the easiest programming language to understand" is DexBasic more easiest, or actually slightly harder?? :?

Logically, if history is a guide, in a few months you will have invented DexC, a yet even more easiest way to create assembly code, with all the power of low-level code and even more user friendly. ;)

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12123
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Programming in Basic on Bare Metal Tutorial 1

Tue Jul 24, 2012 12:02 pm

For what it's worth, I think that using macro assembler as a starting point for bare metal programming is a real good idea, and i'm puzzled about the negative attitude it seems to get from people who seem to be only familiar with more traditional ways of creating code.

It can have all the power of a higher language, but more control than any compiler.
Like forth, it can be its own "operating system", but without the constraints that Forth imposes.

In short, I like it. :P

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 1

Tue Jul 24, 2012 2:25 pm

yes - you are doing gods work
Ostendo ignarus addo scientia.

bobc
Posts: 86
Joined: Fri Apr 06, 2012 8:01 am

Re: Programming in Basic on Bare Metal Tutorial 1

Tue Jul 24, 2012 5:05 pm

mahjongg wrote:For what it's worth, I think that using macro assembler as a starting point for bare metal programming is a real good idea, and i'm puzzled about the negative attitude it seems to get from people who seem to be only familiar with more traditional ways of creating code.

It can have all the power of a higher language, but more control than any compiler.
Like forth, it can be its own "operating system", but without the constraints that Forth imposes.

In short, I like it. :P
Why do you think K&R invented C? Was writing Unix in C a bad idea?

As a professional embedded software developer with 30 years experience, perhaps my opinion is biased towards modern programming practice, but it is not uninformed.

However, I understand exactly why people want to do things the hard way: they enjoy the challenge. They get a greater sense of achievement, even if there was a far more efficient way to do the task. It's like building a house out of matchsticks. It's a great challenge, even if an artificial one. But it has nothing to do with being a good idea.

Trust me, there are very few jobs for programmers who only know assembly language.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 1

Tue Jul 24, 2012 8:30 pm

Thanks everyone for your support and those that do not like the idea thats fine too.
But remember i am not destroying anything, just giving people a new option.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 1

Tue Jul 24, 2012 9:02 pm

And we're not talking about open heart surgery - it's just a hobby and not worth getting upset about.

What's 'easy' and obvious for some people can seem peculiar and daft to others - depends how your brain works and where you're comming from - its a point a view - there's no need to take a fundamental stance.

I've managed to earn a bit of money through web design recently and did it the 'hard' way. I hand coded every single piece using just notepad, HTML, SQL, CSS and PHP, even though I own the Adobe Creative Suite, which I bought for over £1000 with a business start-up grant.

A maestro user of the Creative Suite would probobly laugh at me and delight in telling me how they could have acheived better results in a fraction of the time and then gone to the beach.

But I don't care - for me the learning curve of learning Dreamweaver (and the price of going on a course) was greater than that of teaching myself PHP (which is very similar to C/C++ which I already knew) - I already also had some experience of SQL through using MS Access and I enjoyed expanding my knowledge of CSS and HTML.

I now struggle in seeing the point of learning how to use Dreamweaver and suspect that I have greater flexability in doing things the 'hard' way and that I would better be able to fix things if they go wrong.

The point I'm making is that there is not really an 'easy' way to do anything and whats 'easiest' for you depends on what you already know/understand and how you think.

I expect some pain if I take the plunge into assembler, but would also enjoy getting a better insight into how the hardware functions.

I don't think this would make me a better human being than anyone else, but I expect it would give me a more unique insight into higher level programming, and additional tools should I ever need them.

There are posts from accomplished professional C# programmers on another thread yearning to get back to basics as they feel alienated from the hardware - so assembler is not irrelivant or dead.

Fbasic seems to me to be just a vaneer to make assembler more palatable, which is fine for a noob like me.
Ostendo ignarus addo scientia.

Return to “Bare metal, Assembly language”