flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > fprint "%d = %b \n",[x],[y]

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
l_inc wrote:
fasmnewbie
Quote:
1. Codes will get lots and lots messy when using procedures.

How? I see exactly the opposite. As I said before, procedures contain mostly pure code representing the essential cpu actions for solving a task, while macros require to mix cpu instructions with assembly directives making you think in multiple processing stages in parallel. The latter is much messier and harder to handle.

Quote:
2. Procs and stacks are Chapter 5 in most assembly syllabus.

Well... What chapter are the macrodefinitions and the related fasm quirks? Smile
If you view it from the perspective of a user of your "idea book", then the interface is almost the same:
Code:
;invoking as a macro:
fprt "Your numbers are %d and %d\n",[x],40
;invoking as a procedure:
stdcall fprt, "Your numbers are %d and %d\n",[x],40    

Is your point just about the complexity of typing that additional stdcall in front of the procedure name?

If you view it from the perspective of a developer of macros or procedures, then you still either learn how to write macros or you learn how to write procedures. I can't see how one is easier than the other. Btw. stack usage is equally important for both.


l_inc,

Let me demonstrate to you how the use of macro can greatly and conveniently speed up Teaching and Learning Process without depending on procs (at least not yet)

Code:
org 100h
include 'lib16.inc'

;Lesson 1.2 ROTATE LEFT
pbin [x]  ;Prints x in binary form...
rol [x],1 ;Can I really rotate [x] by 1 bit left??
line      ;wait... where's l_inc? jmp DOwN
pbin [x]  ;oh, I just did!! Seee!! I learned that fast, huh??
pquit
x dw 30

;DOwN:
;Lesson 5.12 STACK FRAME & PROCEDURE CALLS
;l_inc still teaching how to setup stack frame to newbies...
;So that newbies can call PROCS a mile long below....
;half way.... wait, what is stdcall???... on to stdcall
;... six months later..
;... so this is how ROL works.
;... thank you l_inc for teaching us about procs to test ROL    



Now on to Lesson 2 (transition):

Code:
org 100h
include 'lib16.inc'

;Lesson 1.3 XCHG

;Whiteboard erased with no code leftovers
;Using exactly the same source file
;No worries about stack frames. no miles long procs to care about
;Quick and dirty lesson, the VISUAL WAY
pquit    



Lesson 2:

Code:
org 100h
include 'lib16.inc'

;Lesson 1.3 XCHG
mov ax,4142h
prtr ax  ;Confirm it
xchg al,ah  ;Can I really xchange it?
prtr ax ;Great. I just did exchange the content of two byte registers

pquit    


Now you see, this is the kind of learning convenience I been talking about. At this stage, I don't see why newbies should be bothered with procs and stack frames just yet, while learning ROL and XCHG visually in less than 2 minutes, hands-on! Imagine how a newbies learning experience and confidence can be greatly enhanced when they see exactly what's the effect of the instructions.

I have nothing against procs. You got me wrong there.
Post 25 Feb 2014, 16:55
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
AsmGuru62 wrote:
One day I will write a manual on OllyDbg with images and stuff, so every new coder will be able to debug their code.


That would be nice Guru. This is the kind of help to newbies that we should promote on this board. When I first came into contact with FASM, I was so surprised to see that nobody's is offering students/newbies anything. Is FASM intended for seasoned and elite programmers only?

The first tutorial I saw was from "Jakash" or something. Then there's vid's short tutorial and then FASM's docs and then this board and then you are on your own. That's where my motivation came from (only two years later when I started FASM as a serious hobby). I started with prtc macro, then prtbin and then the prtr macros just to help my self understand how all these things work. And then I thought, why not share these macros with others so that they don't have PITA while learning FASM.

I don't blame Privalov for this really. He's done a great job providing us a nice assembler and I think he's contributing enough. No offense to privalov.
Post 25 Feb 2014, 17:38
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Code:
;Lesson 1.2 ROTATE LEFT. Revisited.
org 100h 
include 'macro\proc16.inc'
postpone { include 'lib16.inc' }

stdcall pbin,[x]  ;Prints x in binary form... 
rol [x],1         ;Can you really rotate [x] by 1 bit left?? 
stdcall line
stdcall pbin,[x]  ;oh, you just did!! Seee!! You learned that fast, huh?? 
stdcall pquit     ;— wait, what is stdcall?
                  ;— It's a macro. Just use it, otherwise IT WON'T WORK!
x dw 30    

_________________
Faith is a superposition of knowledge and fallacy
Post 25 Feb 2014, 21:16
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
l_inc wrote:
fasmnewbie
Code:
;Lesson 1.2 ROTATE LEFT. Revisited.
org 100h 
include 'macro\proc16.inc'
postpone { include 'lib16.inc' }

stdcall pbin,[x]  ;Prints x in binary form... 
rol [x],1         ;Can you really rotate [x] by 1 bit left?? 
stdcall line
stdcall pbin,[x]  ;oh, you just did!! Seee!! You learned that fast, huh?? 
stdcall pquit     ;— wait, what is stdcall?
                  ;— It's a macro. Just use it, otherwise IT WON'T WORK!
x dw 30    


Hahaha. Man, that's funny. I knew it that you'd go there . hahaha Laughing

Maybe next time with "proc16". I wasn't aware of this undocumented feature until just recently. But hey, If newbies can learn fast by using the macro set, I will be very happy, provided that they use it correctly to probe and test their code. They can even use the macro to "debug" on-the-fly while learning about procs. Because in the end, they will not be using any of it once they have completed their code. It serves its purpose well as a tool.

And that's a nice thing about that macro set. No extra overhead - not even a single byte committed to their main program after completion.

Since I am thinking of updating the macros soon, maybe you can contribute a macro or two to the existing set. I am still missing random number utility. Math is really not my thing.

I really appreciate your help (again). Thanks.
Post 26 Feb 2014, 02:21
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Quote:
I wasn't aware of this undocumented feature until just recently

I knew, there must be something missing in your argumentation in favor of macros. More revelations to come Smile (below). Not sure however, what you mean by "undocumented". Procedures in general are quite good documented. About the existence of the 16-bit version of the procedure macros I didn't know either, but I was sure, people must have already been thinking about that. It's an easy modification after all.
Quote:
No extra overhead - not even a single byte committed to their main program after completion

I'd like to present one more astonishing fact about procedures (proc macro). Procedures also do not add any single byte to the program, unless you explicitly call them. This is particularly documented even in the wiki.
Quote:
maybe you can contribute a macro or two to the existing set

I'm more on writing very general purpose macros, that produce very little code if any at all. And those should not add an extensive syntax with lots of peculiarities. Once you start forcing people to narrow their code down to your specific abstractions not consistent with their own coding style or macro sets, they will refuse to make use of your work.

Therefore I prefer to write something "useful for anyone". Like displaying binary contents:
Code:
match ,
{
    local begin_s, base_ns, mload_s, base_s, awidth_ns, np_s
    
    macro dispmem_ base, awidth=8, np='.' ;display base, address width, nonprintable characters
    \{
        \local begin,base_n,awidth_n,mload,buf,omit
        
        define begin_s begin
        define base_ns base_n
        define awidth_ns awidth_n
        define mload_s mload
        define base_s base
        define np_s np

        begin = $
        match any, base \\{ base_n = base \\}
        awidth_n = awidth

        macro mload \\{\\}
        macro org [arg] \\{ \\common match =omit,omit
        \\\{
            \\\local ..space, sbegin, send
            sbegin = begin
            send = $
            ..space::

            org arg
            begin = $

            macro mload
            \\\\{
                mload
                purge mload
                match , base \\\\\{ base_n = sbegin \\\\\}
                dq base_n,send-sbegin
                repeat send-sbegin
                    load buf byte from ..space:sbegin+(%-1)
                    db buf
                end repeat
                match any, base \\\\\{ base_n = base_n+(send-sbegin) \\\\\}
            \\\\}
        \\\} match +,omit \\\{ org arg \\\} \\}
        macro virtual [arg]
        \\{
            common virtual arg
            define omit +
        \\}
        struc virtual [arg]
        \\{
            common . virtual arg
            match =end,. \\\{ restore omit \\\}
        \\}
        macro dispmem_ [arg]
        \\{
            common
                display 'Error: _dispmem missing',13,10
                err
        \\}
    \}
    
    macro _dispmem
    \{
        \local dig,buf,curptr,displen,b,e,..space,ssize,spaceptr
        match =np_s,np_s
        \\{
            display "Error: dispmem_ missing",13,10
            err
        \\}
        
        ssize = $-begin_s
        ..space::
        virtual at 0
            match mload,mload_s
            \\{
                mload
                purge mload
            \\}
            match , base_s \\{ base_ns = begin_s \\}
            dq base_ns, ssize
            repeat ssize
                load buf byte from ..space:begin_s+(%-1)
                db buf
            end repeat
            
            spaceptr = $$
            while spaceptr < $
                load b qword from spaceptr
                load e qword from spaceptr+8
                if b >= 1 shl 63
                    b = b - 1 shl 63 - 1 shl 63
                end if
                e = b+e
                spaceptr = spaceptr+16
                
                if e-b > 0
                    times awidth_ns display ' '
                    display '   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F',13,10
                    
                    curptr = b and not $F
                    displen = ((e+$F) and not $F - curptr) shr 4
                    repeat displen
                        ;display address
                        repeat awidth_ns
                            dig = curptr shr ((awidth_ns-%)*4) and 0Fh+'0'
                            if dig > '9'
                                dig = dig-'0'+('A'-10)
                            end if
                            display dig
                        end repeat
                        display ': '
                        
                        ;display hex data
                        repeat $10
                            if curptr+(%-1) < b | e <= curptr+(%-1)
                                display '   '
                            else
                                load buf byte from spaceptr+(%-1)+(curptr-b)
                                repeat 2
                                    dig = buf shr ((2-%)*4) and 0Fh+'0'
                                    if dig > '9'
                                        dig = dig-'0'+('A'-10)
                                    end if
                                    display dig
                                end repeat
                                display ' '
                            end if
                        end repeat
                        display ' |'
                        
                        ;display ascii data
                        repeat $10
                            if curptr+(%-1) < b | e <= curptr+(%-1)
                                display ' '
                            else
                                load buf byte from spaceptr+(%-1)+(curptr-b)
                                if buf < $20
                                    match np,np_s \\{ display \\`np \\}
                                else
                                    display buf
                                end if
                            end if
                        end repeat
                        display '|',13,10
                        curptr = curptr + $10
                    end repeat
                end if
                spaceptr = spaceptr+(e-b)
            end while
        end virtual
        
        purge org,virtual
        restruc virtual
        restore begin_s, base_ns, mload_s, base_s, awidth_ns, np_s
        purge dispmem_
    \}
}    

This one may seem to be a bit complicated, but I actually consider it to be of high quality, cause it's from time when I finally came up with a universal architecture for paired macros, which does not introduce any side effects. What I wanna say is that it's not just for a subset of users, and everyone may find it useful and very easy to use:
Code:
dispmem_
    ;any code, any data, any other macros here (limited by common sense, you know)
_dispmem    

It can be used with any code and won't interfere with other macro architectures. And no one is gonna think like "may be it produces suboptimal code and I could invent the wheel again and do better", because it does not produce any code. Similarly code encryption, formatting, structure definition, data allocation and reallocation etc. macros can have same constraints. However macros that produce some necessary amount of code can also be very handy (like the proc or invoke macro) and I by no means say, that macros must not produce code, because that is actually their initial and primary purpose.

P.S. The above macro is better to use with the console version of fasm with a third party GUI (like notepad++) configured to display monospaced font, cause fasmw has a very small and not sizable display window.

_________________
Faith is a superposition of knowledge and fallacy
Post 26 Feb 2014, 13:28
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
l_inc wrote:
fasmnewbie
Quote:
I wasn't aware of this undocumented feature until just recently

I knew, there must be something missing in your argumentation in favor of macros. More revelations to come Smile (below). Not sure however, what you mean by "undocumented". Procedures in general are quite good documented. About the existence of the 16-bit version of the procedure macros I didn't know either, but I was sure, people must have already been thinking about that. It's an easy modification after all.
Quote:
No extra overhead - not even a single byte committed to their main program after completion

I'd like to present one more astonishing fact about procedures (proc macro). Procedures also do not add any single byte to the program, unless you explicitly call them. This is particularly documented even in the wiki.
Quote:
maybe you can contribute a macro or two to the existing set

I'm more on writing very general purpose macros, that produce very little code if any at all. And those should not add an extensive syntax with lots of peculiarities. Once you start forcing people to narrow their code down to your specific abstractions not consistent with their own coding style or macro sets, they will refuse to make use of your work.

Therefore I prefer to write something "useful for anyone". Like displaying binary contents:
Code:
match ,
{
    local begin_s, base_ns, mload_s, base_s, awidth_ns, np_s
    
    macro dispmem_ base, awidth=8, np='.' ;display base, address width, nonprintable characters
    \{
        \local begin,base_n,awidth_n,mload,buf,omit
        
        define begin_s begin
        define base_ns base_n
        define awidth_ns awidth_n
        define mload_s mload
        define base_s base
        define np_s np

        begin = $
        match any, base \\{ base_n = base \\}
        awidth_n = awidth

        macro mload \\{\\}
        macro org [arg] \\{ \\common match =omit,omit
        \\\{
            \\\local ..space, sbegin, send
            sbegin = begin
            send = $
            ..space::

            org arg
            begin = $

            macro mload
            \\\\{
                mload
                purge mload
                match , base \\\\\{ base_n = sbegin \\\\\}
                dq base_n,send-sbegin
                repeat send-sbegin
                    load buf byte from ..space:sbegin+(%-1)
                    db buf
                end repeat
                match any, base \\\\\{ base_n = base_n+(send-sbegin) \\\\\}
            \\\\}
        \\\} match +,omit \\\{ org arg \\\} \\}
        macro virtual [arg]
        \\{
            common virtual arg
            define omit +
        \\}
        struc virtual [arg]
        \\{
            common . virtual arg
            match =end,. \\\{ restore omit \\\}
        \\}
        macro dispmem_ [arg]
        \\{
            common
                display 'Error: _dispmem missing',13,10
                err
        \\}
    \}
    
    macro _dispmem
    \{
        \local dig,buf,curptr,displen,b,e,..space,ssize,spaceptr
        match =np_s,np_s
        \\{
            display "Error: dispmem_ missing",13,10
            err
        \\}
        
        ssize = $-begin_s
        ..space::
        virtual at 0
            match mload,mload_s
            \\{
                mload
                purge mload
            \\}
            match , base_s \\{ base_ns = begin_s \\}
            dq base_ns, ssize
            repeat ssize
                load buf byte from ..space:begin_s+(%-1)
                db buf
            end repeat
            
            spaceptr = $$
            while spaceptr < $
                load b qword from spaceptr
                load e qword from spaceptr+8
                if b >= 1 shl 63
                    b = b - 1 shl 63 - 1 shl 63
                end if
                e = b+e
                spaceptr = spaceptr+16
                
                if e-b > 0
                    times awidth_ns display ' '
                    display '   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F',13,10
                    
                    curptr = b and not $F
                    displen = ((e+$F) and not $F - curptr) shr 4
                    repeat displen
                        ;display address
                        repeat awidth_ns
                            dig = curptr shr ((awidth_ns-%)*4) and 0Fh+'0'
                            if dig > '9'
                                dig = dig-'0'+('A'-10)
                            end if
                            display dig
                        end repeat
                        display ': '
                        
                        ;display hex data
                        repeat $10
                            if curptr+(%-1) < b | e <= curptr+(%-1)
                                display '   '
                            else
                                load buf byte from spaceptr+(%-1)+(curptr-b)
                                repeat 2
                                    dig = buf shr ((2-%)*4) and 0Fh+'0'
                                    if dig > '9'
                                        dig = dig-'0'+('A'-10)
                                    end if
                                    display dig
                                end repeat
                                display ' '
                            end if
                        end repeat
                        display ' |'
                        
                        ;display ascii data
                        repeat $10
                            if curptr+(%-1) < b | e <= curptr+(%-1)
                                display ' '
                            else
                                load buf byte from spaceptr+(%-1)+(curptr-b)
                                if buf < $20
                                    match np,np_s \\{ display \\`np \\}
                                else
                                    display buf
                                end if
                            end if
                        end repeat
                        display '|',13,10
                        curptr = curptr + $10
                    end repeat
                end if
                spaceptr = spaceptr+(e-b)
            end while
        end virtual
        
        purge org,virtual
        restruc virtual
        restore begin_s, base_ns, mload_s, base_s, awidth_ns, np_s
        purge dispmem_
    \}
}    

This one may seem to be a bit complicated, but I actually consider it to be of high quality, cause it's from time when I finally came up with a universal architecture for paired macros, which does not introduce any side effects. What I wanna say is that it's not just for a subset of users, and everyone may find it useful and very easy to use:
Code:
dispmem_
    ;any code, any data, any other macros here (limited by common sense, you know)
_dispmem    

It can be used with any code and won't interfere with other macro architectures. And no one is gonna think like "may be it produces suboptimal code and I could invent the wheel again and do better", because it does not produce any code. Similarly code encryption, formatting, structure definition, data allocation and reallocation etc. macros can have same constraints. However macros that produce some necessary amount of code can also be very handy (like the proc or invoke macro) and I by no means say, that macros must not produce code, because that is actually their initial and primary purpose.

P.S. The above macro is better to use with the console version of fasm with a third party GUI (like notepad++) configured to display monospaced font, cause fasmw has a very small and not sizable display window.


Oh man, you are speaking biohazard again. This is baldr, revolution and privalov's language when they sleepwalking. Not mine Surprised

But that conversion ifs looks nice to fit into my macro set Laughing . I just dont even know where to start copying. I dont speak biohazard.
Post 26 Feb 2014, 15:42
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Quote:
you are speaking biohazard

OK. Let me try again. The whole biohazard from the first block of code should be completely saved in a separate file, say "general.inc", together with whatever other biohazards you wanna be there. And here's the nature friendly and as clear as bidistillate usage:
Code:
include 'general.inc'
use32

dispmem_
    org 0
        db 'Hello, I''m not a biohazard. I''m simple and clear'
    org 0
        db 'Hmm... Is it possible to multiply by 4 in printable ASCII x86?'
    org $100
        imul eax,4
    org 0
        db 'No. No luck here'
        db 'Maybe like this?'
    org $100
        add eax,eax
        add eax,eax
    org 0
        db 'Nope. This does not fit again'
    org $100
        shl eax,2
    org 0
        db 'Wtf?! All the time these characters below 0x20!'
    org $100
        shl eax,1
        shl eax,1
    org 0
        db 'Yuhuu! Now I can start writing my own exploit!'
_dispmem    

Compile with fasm.exe (not fasmw.exe!) and look at the compilation output.

_________________
Faith is a superposition of knowledge and fallacy
Post 26 Feb 2014, 18:18
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Quote:
I am still missing random number utility. Math is really not my thing

I missed this one. One doesn't really need much math in order to implement existing algorithms. There are plenty of well-studied comprehensively described PRNGs with very good characteristics. However depending on whether you need a runtime or compile time PRNG, you might confront a seeding problem. E.g., %t is not a dreamlike source of entropy.

_________________
Faith is a superposition of knowledge and fallacy
Post 26 Feb 2014, 20:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
Code:
include 'http://random.org'    
Post 26 Feb 2014, 20:08
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
fasmnewbie: Standard functions/proc/edures (push-call) are recommended for library routines (example: memcpy, printf). Macros are perfectly suitable for language features/constructs that only produce a few instructions - variables, arithmetic, comparisons, loops, etc - but they can be dangerous, wasteful and not good for library routines that are reusable 2+ times... except when testing.

Example: In this macro, eax/ecx cannot be sent as parameters. If it were a function, it would not matter since it would access a copy of the register values on the stack (not that it should be a function, only an example):
Code:
macro zero.bit v, i { ; v&=~(1<<i)
 mov eax, 1
 mov ecx, i
 shl eax, cl
 not eax
 and v, eax
}    
Just posted new ideas for C-style macro language - Super+C ML.
Post 27 Feb 2014, 03:51
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
m3ntal wrote:
fasmnewbie: Standard functions/proc/edures (push-call) are recommended for library routines (example: memcpy, printf). Macros are perfectly suitable for language features/constructs that only produce a few instructions - variables, arithmetic, comparisons, loops, etc - but they can be dangerous, wasteful and not good for library routines that are reusable 2+ times... except when testing.

Example: In this macro, eax/ecx cannot be sent as parameters. If it were a function, it would not matter since it would access a copy of the register values on the stack (not that it should be a function, only an example):
Code:
macro zero.bit v, i { ; v&=~(1<<i)
 mov eax, 1
 mov ecx, i
 shl eax, cl
 not eax
 and v, eax
}    
Just posted new ideas for C-style macro language - Super+C ML.


I offer no counter arguments of what you are saying m3ntal. But I have different variables to satisfy. While people here are talking about how many bytes and clock cycles they can save using a proc against a macro, my variables are how many teaching hours/cost one can save by finding a teaching methods that are;

1. clean, with minimal distractions
2. fast and easy
3. effective

Thats my job and my objective. And one method I can find is through the use of macros, particularly when dealing with 16-bit programs and the target clients are students with HLL background. I hold no teaching position by the way. My job is to oversee pedagogical matters.

I see your macro has one AND instruction. One student could ask "what's the effect of ANDing v against (E)ax. Can you prove it to me?" This is how a macro call can do the job best. A simple clean 5-line code;

Code:
org 100h
include 'lib16.inc'

mov ax,1001110110110110b
prtreg ax,-b
and ax,0FF00h
prtstr "==> and ax,0FF00H\n"
prtreg ax,-b
exitp    


The output. Descriptive and visual:
Code:
ax:9DB6 [10011101 10110110]
==> and ax,0FF00H
ax:9D00 [10011101 00000000]    



This is how fast, clean and effective it can be by using macros. Short, simple, descriptive and with minimum unnecessary distractions (push, pop, calls, and the procs and the likes just to learn AND by visual approach). Imagine the time that can be saved this way.

And for the whole semester (some even offer only half-semester assembly course!), a teacher/instructor and the students can use only 2 files to learn almost all about popular x86 instructions using this way. You have no idea how this can greatly save teaching preparations costs, instructors burden and time.

Now that's my variables. My main business is pedagogy. ANd from pedagogy point of view, this "proc" approach is messy and distracting until its time to really learn about 16-bit stack and procedures.

Code:
org 100h

mov ax,1001110110110110b
push ax  ;<--- unnecessary distactions
call prtreg
pop ax   ;<--- unnecessary distractions
and ax,0ff00h ;<--- just to learn this!
push boring
call prtstr
pop whatever ;needs to be popped
push ax  ;<--- unnecessary distractions
call prtreg
push 0   ;<--- more distractions
call [exit]
boring db "==> and ax,0FF00H\n" ;<---- not cool

prtreg:
looong
dirty
distraction...
ret

prtstr:
another miles long
distractions
...
ret

exit
    


Remember, we are talking about 16-bit FASM assembly here without using and extended header (not to mention a linker Very Happy) where information hiding for the procs cannot be fully implemented.
Post 27 Feb 2014, 16:25
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Overquoting is a bad habit.

_________________
Faith is a superposition of knowledge and fallacy
Post 28 Feb 2014, 11:19
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
l_inc wrote:
fasmnewbie
Overquoting is a bad habit.
sorry. Didnt know. I trird your biohazard and it has some nice features of displaying memory dump. But i dont know what else to do with it. How can I modify it so that I can see some range of memory content. Way too advance for me man.

Like dispmem [here] ... [there] dispmem. Is it even possble because I see itresembles a debugger output.
Post 28 Feb 2014, 13:35
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
oh man, Your biohazard is nasty!!!
Post 28 Feb 2014, 13:57
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
I don't really understand the problem. You can enclose almost any part of your listing into the dispmem_ ... _dispmem block. And you can do it multiple times for different pieces of your listing.

Do you mean, you'd like to specify an address value and size without enclosing the specified block into the "dispmem parentheses"?

_________________
Faith is a superposition of knowledge and fallacy
Post 28 Feb 2014, 14:02
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
l_inc

u dont have to. I just figured out how it works.
Thanks for your biohazard. Thats a mastrpiece man! Supercool Very Happy
Post 28 Feb 2014, 15:23
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
The topic that I am riding on has derailed.
Post 27 Mar 2014, 10:45
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
sid123 wrote:
The topic that I am riding on has derailed.


sid123

Sorry. Kind of busy lately. Do you need the complete source?
Don't have time to clean up my macro set. But it goes something like this.

Code:
;------------------------
macro fprint fmt*,[args*]
;------------------------
{
        common
        pusha
        if fmt eqtype ''
           fprts fmt,args
        else
           fprtv fmt,args
        end if
        popa
}
;FPRINT sub macro
;do not use directly
macro fprts fmt*,[args*]
{
        reverse push args
        common
        local .loop,.cha,.oct,.intg,.b
        local .bin,.hex,.ok,.line,.done,.sig

        xor si,si
        mov ah,0eh
.loop:  cmp byte[cs:.b+si],0
            je .done
        cmp word[cs:.b+si],'\n' ;new line
            je .line
        cmp word[cs:.b+si],'%d' ;for signed
            je .sig
        cmp word[cs:.b+si],'%u' ;for unsigned
            je .intg
        cmp word[cs:.b+si],'%b' ;for binary
            je .bin
        cmp word[cs:.b+si],'%h' ;for hex
            je .hex
        cmp word[cs:.b+si],'%o' ;for octal
            je .oct
        cmp word[cs:.b+si],'%c' ;for char (dw)
            je .cha
        mov al,byte[cs:.b+si]
        int 10h
        inc si
        jmp .loop
.cha:   pop bx
        prtchar bl
        jmp .ok
.oct:   pop bx
        prtoct bx,-line
        jmp .ok
.hex:   pop bx
        prthex bx,-line
        jmp .ok
.bin:   pop bx
        prtbin bx,-t,-line
        jmp .ok
.intg:  pop bx
        prtint bx,,-line
        jmp .ok
.sig:   pop bx
        prtint bx,-s,-line
        jmp .ok
.line:  line
.ok:    add si,2
        jmp .loop
        .b db fmt,0 ;local string
.done:
}
;FPRINT sub-macro
;do not use directly
macro fprtv fmt,[args]
{
        reverse push args
        common
        local loo1,cha1,oct1,intg1,sig1
        local bin1,hex1,ok1,lin1,done1

        mov si,fmt
        mov ah,0eh
loo1:   cmp byte[si],0
            je done1
        cmp word[si],'\n'
            je lin1
        cmp word[si],'%d'
            je sig1
        cmp word[si],'%u'
            je intg1
        cmp word[si],'%b'
            je bin1
        cmp word[si],'%h'
            je hex1
        cmp word[si],'%o'
            je oct1
        cmp word[si],'%c'
            je cha1
        mov al,byte[si]
        int 10h
        inc si
        jmp loo1
cha1:   pop bx
        prtchar bl
        jmp ok1
oct1:   pop bx
        prtoct bx,-line
        jmp ok1
hex1:   pop bx
        prthex bx,-line
        jmp ok1
bin1:   pop bx
        prtbin bx,-t,-line
        jmp ok1
intg1:  pop bx
        prtint bx,,-line
        jmp ok1
sig1:   pop bx
        prtint bx,-s,-line
        jmp ok1
lin1:   line
ok1:    add si,2
        jmp loo1
done1:
}
    


Thanks to baldr and l_inc

Usage:
Code:
fprint "Your numbers are %u,%o and %d\n",[x],43h,-55    


or

Code:
fprint mystr,1011b,[y],177777o
mystr db "Hello\n%u\n%d\n%h\n",0
y dw -34h    


Edit: not %d but %u for unsigned.
Post 31 Mar 2014, 02:57
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
well i highly suggest you to put all of your system dependent (putchar, readchar, open, close, write, read etc.) functions inside another file called "syscalls.inc" or whatever you prefer, this way it'll be easier for others to understand and use. Smile (not to mention that it'll be readable as well as portable too....)
Post 21 Apr 2014, 12:08
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
sid123 wrote:
well i highly suggest you to put all of your system dependent (putchar, readchar, open, close, write, read etc.) functions inside another file called "syscalls.inc" or whatever you prefer, this way it'll be easier for others to understand and use. Smile (not to mention that it'll be readable as well as portable too....)


I'll see what I can do. It may take me some time to read my own code though. Left it for quite some time. Now I am having trouble understanding what I wrote. LOL.
Post 03 May 2014, 16:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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 GitHub, YouTube, Twitter.

Website powered by rwasa.