flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > .

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:55; edited 2 times in total
Post 21 Nov 2008, 21:35
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7751
Location: Kraków, Poland
Tomasz Grysztar
Check out the Sphinx C-- project.
Post 21 Nov 2008, 21:44
View user's profile Send private message Visit poster's website Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
Also check Octavio's Octasm because it has a syntax close to this what you seek.

However rewriting C code in ASM is not a good idea.

Instead, if you have an algorithm written in C, do try to understand the algorithm in C first and in concepts later on and then rethink and re-implement it in ASM while maintaining an ASM kind of HLL structure by using multiple .if .elseif .else .endif, using invoke/stdcall extensively and PROC and ARG and LOCAL.

Many times HLL code writers destroy an algorithm or miss algorithms completely because they do not "think in ASM concepts"

I have seen that there is a big temptation to copy paste algorithms and programs from the existing C or HLL base just to get "a head".

However this is a bad idea because you skip the (arguably slow) process of learning and understanding just to get something working "faster"

And this kind of attitude will back fire later on.
Post 22 Nov 2008, 04:47
View user's profile Send private message Visit poster's website Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:55; edited 1 time in total
Post 22 Nov 2008, 12:31
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mikegonta,

For simple instructions like add eax, ebx notation is obvious, but what about more complex one (CISC, heh? Wink), xchg eax, ebx for example? Or MMX/SSE#/whatever…

By the way, eax = BYTE *ptr; and movzx eax, BYTE [ptr] aren't equivalent, are they? May be eax = *(unsigned BYTE *)&ptr;? Wink
Post 22 Nov 2008, 14:49
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:55; edited 1 time in total
Post 22 Nov 2008, 15:36
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:56; edited 2 times in total
Post 22 Nov 2008, 18:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
The ADC looks very problematic. One needs to be careful about opcode reordering due to optimisation steps. Remember that x86 has a fixed assignment of which opcodes update the flags, so the carry can easily become overwritten by intervening instructions.
Post 22 Nov 2008, 18:12
View user's profile Send private message Visit poster's website Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:56; edited 1 time in total
Post 22 Nov 2008, 18:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
mikegonta wrote:
However since all operators have equal precedence the ordering is completely under the programmer's control.
Oh! It is not immediately clear where the carry is from this code you posted above:
Code:
  eax += ebx - ecx;    
One has to see the ASM before it becomes clear where the carry is generated.
Code:
// which would translate to
  add eax, ebx
  sub eax, ecx    


But what about:
Code:
eax += ebx - ecx * edx + esi;    
If all operators have equal precedence then how is it going to be evaluated? L-to-R?
Post 22 Nov 2008, 18:32
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mikegonta,

OK, let's make it straight: ptr in your example is constant or variable? void * const ptr = 0xB8000; or void *ptr; (not strictly correct, but enough to catch the difference)?

Terse appears to be too terse Wink, it reminds me APL on ASCII diet. Assembly programming is complex enough to make it unnecessary cryptic. Do you remember C operators' precedence?
mikegonta wrote:
I would prefer the functions to be spelled out instead of mnemonic:
What about
Code:
exchange equ xchg
pushAll equ pusha    
Wink

I think, verbosity of pure assembly is a merit, not flaw. You can use macros to automate repetitive tasks, for example to define new instruction
mov sreg2, sreg1 having opcode 000sr110 000sr111 with side-effect of setting [sp-2] Wink

revolution,

I thought Mike was about new syntax for instructions, not granting compiler right to evaluate run-time expressions…
Post 22 Nov 2008, 19:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
baldr wrote:
I thought Mike was about new syntax for instructions, not granting compiler right to evaluate run-time expressions…
Okay we need Mike to clarify that. But this code (posted by Mike) seem to show complex expression evaluation:
Code:
  eax += ebx - ecx;    
Post 22 Nov 2008, 19:28
View user's profile Send private message Visit poster's website Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:56; edited 1 time in total
Post 22 Nov 2008, 19:34
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:57; edited 1 time in total
Post 22 Nov 2008, 19:39
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:57; edited 1 time in total
Post 22 Nov 2008, 19:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
mikegonta wrote:
So
Code:
  eax += ebx - ecx * edx + esi;
//  add eax, ebx
//  sub eax, ecx
//  mul eax, edx
//  add eax, esi
    
Now that is just scary and crying out for ease of making subtle and hard to find bugs.
Post 22 Nov 2008, 19:44
View user's profile Send private message Visit poster's website Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:57; edited 1 time in total
Post 22 Nov 2008, 19:49
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mikegonta,

OK, compound assignment (op=) should be banned as counter-intuitive (consider eax –= ebx – ecx; Wink). What about beloved mul r/m?
edx:eax = eax * r/m32?

I'm not nit-picking. To describe most of useful instructions it will take several lines (if not pages) of C-like pseudocode. New syntax only for a few instructions? Does it worth efforts?
Post 22 Nov 2008, 19:54
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta
[ Post removed by author. ]


Last edited by mikegonta on 28 Jan 2009, 08:58; edited 1 time in total
Post 22 Nov 2008, 20:18
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mikegonta,

"Merely notation shortcut"? In C
expr1 += expr2 is semantically different from
expr1 = expr1 + expr2

eax -= ebx - ecx compiled as eax -= (ebx + ecx) will be unpleasant surprise for almost any C programmer.

Can rcl qualify as simple instruction? Wink

Why don't use postfix notation? It's unambiguous and you'll end up with another FORTH compiler… Wink

Jokes aside, may be you should try to write specification for that syntax (just syntax, i.e. rules for statement composition, for a small subset of instructions of your choice)? It's not easy to develop consistent yet simple to use syntax.
Post 22 Nov 2008, 21:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.