Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Compiler (DBPro)

Author
Message
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 10th Dec 2004 04:54 Edited at: 20th Dec 2004 18:44
Simple interpreter / compiler type thing I did this evening.
Nothing too exciting yet - just outputs asm for mathematical expressions.

For example type

1+2-3*4/5

and see the screen fill with ASM

Tomorrow I'll try and do parenthesis (brackets).



Have fun

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
Torrey
20
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 10th Dec 2004 12:53 Edited at: 10th Dec 2004 12:55
Don't forget in ASM, MOVE is really MOV.

Quick snippet:

; Mapping our executable into memory for manipulation
; and execution after converting

xor edx,edx
push edx
push edx
push 0
push 0xf001f
push eax
call [MapViewOfFile]

mov [mAddress],eax

call vpRoutine
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 10th Dec 2004 15:45
Quote: "Don't forget in ASM, MOVE is really MOV."


Not in my version The 68k assembler I have uses move, move.l etc.

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 10th Dec 2004 17:43
Heh, I believe we'd gone through this once
Still unsure why you'd deliberately start on an obsolete system.


empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 10th Dec 2004 18:29 Edited at: 10th Dec 2004 18:30
Nice adaption of the Pascal tut.


Quote: "Still unsure why you'd deliberately start on an obsolete system."

Maybe because the basic principles are the same on "modern" systems? As long as CPUs (and even most VMs) are stack based, the methods are the pretty much the same.

Play Nice! Play Basic!
Version 1.02 available now!
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 10th Dec 2004 18:39
perhaps, but the Pascal Assembler appears to have a few things that David isn't going to find in an Intel-Based Assembler.

i did suggest to him he visited the IRC room to find you, and talk to you about Pascal; as the only time i've developed for a 68k was through GAS, which appears not to have a few of the 'easy' commands that were giving him trouble.


David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 10th Dec 2004 21:53
Quote: "Nice adaption of the Pascal tut. "


Yes I wanted to recreate it from scratch, so I fully understood the concepts.

Raven - Whatever ASM I output doesn't really matter, because I can easily change what's outputted

Empty - I've been having trouble getting my asembler to accept this:

LEA variablename(PC),D0

It says unidentified identifier

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Dec 2004 00:46
Quote: "Empty - I've been having trouble getting my asembler to accept this:"

Which assembler is it and can you post the rest of the code?

Play Nice! Play Basic!
Version 1.02 available now!
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 11th Dec 2004 01:10
I'm using one called easy 68k - it's a 68000 assembler I think - the same type the pascal tutorial uses.

Here's the full code, its a translated version of

var = 2 + 3



I assume the last two store D0 in the variable "var" - but it gives an error on the LEA line. I assume that's because I have to define it first?

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Dec 2004 04:09
Yeah, lea var(PC), A0 stores the address of var (which needs to be defined, var: ds.l 1) in A0. Then Move.l D0, (A0) moves the contents of D0 to the address stored in A0.

Play Nice! Play Basic!
Version 1.02 available now!
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 20th Dec 2004 01:18
The closest I've got to Assembler is failing to write a CHIP-8 emulator

(It works, but I get randomized dots on the screen which look like nothing human, which means I probably got one of the key functions wrong. Oh well.)

Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 20th Dec 2004 16:14 Edited at: 10th Apr 2022 16:44
David,

The parser has defined the label "Var", which the assmebly is expecting to be deifned and PC realtive. The label can appear before or after it's use, but.. Since it's PC relative it must be within a 16bit range (signed) of where it's used.

Since the assembler will not store the absolute address of this variable in memory, but it's offset from where the PC is currectly executing (the LEA opcode), it creates the A0 pointer by basically going A0 = PC + offsetToVariable.

if it were an absolute LEA you could just

Lea.l MyVariable,a0



So you could (define the variables first)
=======================

Bra Start ; skip the data segment

MyVariable: Dc.l 0 ; Define space for a long

Start:
move.l #2,D0
move.l D0,-(SP)
move.l #3,D0
add (SP)+,D0
lea MyVariable(PC),A0 ; << load relative address to MyVariable into A0
move.l D0,(A0)

brk ; force an exception (halt program)


or (define it after),
==========================

move.l #2,D0
move.l D0,-(SP)
move.l #3,D0
add (SP)+,D0
lea MyVariable(PC),A0 ; << load relative address to MyVariable into A0
move.l D0,(A0)

brk ; force an exception (halt program)

MyVariable: Dc.l 0 ; Define space for a long


A better solution would be use a format as RS structures for variables.. This is most compiler like SASC on the amiga do. This means that a register is used as the base addfress of the variable stack

I.e.

Variables:
Blk.l NumberOfVariables ; Define Space for the cleared block LONGS, at the label Variable

At the start of your code, you LEA this into an address register, like A5, A6 say

Lea.l Variables,A5

Next whenever you generate variable access, rather than LEA'ing the absolute address of the variable and then doing a move (LEA's are around 6->8 clock cycles, and two register moves to memory are a bit less, probably 4 clocks.. ).. you can use a fixed 16bit offset to the A5 register.. The compiler just needs to translate that variable name, into it's index on the variable stack.


I.e.
MOve.l #10,(a5) ; move 10 into the first variabe

Move.l #20,1*4(a5( ; move th 20 into the second variable

Etc..

rather than

Lea.l MyVariable(pc),a0
move.l #10,(a0)
Lea.l MyOtherVariable(pc),a0
move.l #20,(a0)


On the 68000 and 68010 there are some opcodes that are not supported in this format, but ya get that

68020 and above support up to 32bit offsets..


LearnToCode with Kevin Picone at www.PlayBASIC.com


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 20th Dec 2004 18:44
Quote: "The parser has defined the label "Var", which the assmebly is expecting to be deifned and PC realtive. The label can appear before or after it's use, but.. Since it's PC relative it must be within a 16bit range (signed) of where it's used. "


Yes I realised that afterwards! When / If I ever finish this, any declarations would be made at the beginning of the program and translted into ASM declarations.

Thanks for the advice anyway, I'll have a look at it.

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 20th Dec 2004 21:51
Well you could do it that way, but then each variable needs to be explicitly declared ahead of time in the source, or the pre-processor has to find declarations. Which can get really messy.

Also, really need to watch the operation width..

I.e.

add (SP)+,D0

should be explicit,

add.l (sp)+,d0

For stuff like brackets, the parser is just being made to focus it's attention upon the characters within the bracket pair, until the there's a firm result (could be syntax error also.. ect) . The result is then exported from the brackets and re-embedded in the expression and the process continues.. until all that remains is the result

While working on strings might be easier to get the head around, i'd really suggest moving to tokens.. It's allows for pre & post processing of the expressions..

Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic - Next Generation Basic (Release V1.05 Out Now)
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 20th Dec 2004 23:04
Quote: "but then each variable needs to be explicitly declared ahead of time"


That's what I'm heading for

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"

Login to post a reply

Server time is: 2024-11-23 16:51:16
Your offset time is: 2024-11-23 16:51:16