flat assembler
Message board for the users of flat assembler.
Index
> DOS > beginner - macro vs calls |
Author |
|
okasvi 09 Mar 2007, 14:26
Too busy to answer to your questions, and I'm sure someone else will, but I suggest printing this to A4 http://smallcode.weblogs.us/wp-content/uploads/2006/05/CheatSheet.png
|
|||
09 Mar 2007, 14:26 |
|
Dex4u 09 Mar 2007, 15:40
Most of your example are just the same has each other, and are sings and roundabouts as to which is best.
But you need to remember a jump (jmp), is a jump to label, with no return, a "call" would return. PS: Once you have learnt some asm in dos, agood next step would be to code in DexOS, as it a like Dos, but with more memory (upto 4 GB) and 32bit pmode. Last edited by Dex4u on 09 Mar 2007, 17:17; edited 1 time in total |
|||
09 Mar 2007, 15:40 |
|
dvlfrnd 09 Mar 2007, 15:52
okasvi & Dex4u , thank you for your directions,
jmp -> yes i realized i was using wrong terminology, i'll correct it |
|||
09 Mar 2007, 15:52 |
|
DOS386 09 Mar 2007, 19:27
Quote:
Nice, NOT only Win32, I just don't understand the "spin" loop Quote: about macros/calls Macros will be removed when assembling. Subs&calls remain. Calls can slow down the program (usually negligible). Repeated usage of large macros will waste memory, subs&calls are better then. Quote:
Exactly the same. mov ax,0 is good enough Quote:
mov ax,0 Quote:
For 32-bit DOS programming you can use DPMI or DexOS, as Dex4u pointed you, like he points everybody in this forum See also the FAQ's on the top of this subforum. _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
09 Mar 2007, 19:27 |
|
Dex4u 09 Mar 2007, 23:21
@NTOSKRNL_VXE, Thats my job, i am a DexOS spammer .
PS: I see your have done some of your own "DexOS spamming" here: http://www.drdosprojects.de/forum/drp_forum/posts/3601.html |
|||
09 Mar 2007, 23:21 |
|
dvlfrnd 10 Mar 2007, 15:27
Thank you NTOSKRNL_VXE,
I read that anything that alters the Instruction Pointer ends up dumping prefetched next instruction bytes from memory and cause you to lose cycles,however i am not sure if this applies to the latest intel processors.(must do more reading) so i believe choosing a macro vs. call is about memory usage vs. speed, which makes sense when put in related context,and your program's needs. I still couldn't figure out where the Instruction Pointer is stored when there is a call. I've read about ARM assembly a little bit and in ARM,the programmer explicitly has to move program counter to link register before the jump,then move link register back int o program counter on return.makes a lot of sense.it is obvious this is done implicitly in intel architecture,just curious how. thanks for the help |
|||
10 Mar 2007, 15:27 |
|
DOS386 10 Mar 2007, 20:39
Quote: I read that anything that alters the Instruction Pointer ends up dumping prefetched next instruction bytes from memory and cause you to lose cycles,however i am not sure if this applies to the latest intel processors.(must do more reading) Considering from your beginnerous questions, you can safely ignore such "problems" for now Also, for DOS development, 80386 compatible code is rather useful then chasing the last "wasted" picosecond on latest intel processors Quote: couldn't figure out where the Instruction Pointer is stored when there is a call. On the stack. _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
10 Mar 2007, 20:39 |
|
dvlfrnd 11 Mar 2007, 02:02
Thanks for the advice,i just like knowing details.
call -> pushes IP to the stack (and does related calculations) ret -> pops stack and jump to the address just like you said |
|||
11 Mar 2007, 02:02 |
|
rugxulo 13 Mar 2007, 09:04
Quote:
The first example doesn't overwrite AX, so that's more convenient, IMO. However, only the second runs on an 8086 (because pushing immediates is supported only on 80186+ ... not that most people care anymore, just FYI). Quote:
AH (high, 8 bits) and AL (low, 8-bits) are the two halfs that compose AX (16-bits). Same goes for BX (BH/BL), CX (CH/CL), DX (DH/DL). I think long mode (AMD64/EM64T) has some other variants too. |
|||
13 Mar 2007, 09:04 |
|
Tomasz Grysztar 13 Mar 2007, 09:40
rugxulo wrote: The first example doesn't overwrite AX, so that's more convenient, IMO. However, only the second runs on an 8086 (because pushing immediates is supported only on 80186+ ... not that most people care anymore, just FYI). Don't forget that the first one is shorter by one byte. For this reason it's used in the size competitions. |
|||
13 Mar 2007, 09:40 |
|
dvlfrnd 13 Mar 2007, 15:58
thanks a lot,i've seen examples of al and ah being set cleverly in different segments of the code to achieve some ax value.
there's one more thing i'm curious about, that is,how to dynamically allocate memory. db directive looks static,as it adds itself up to the end of the executable, how could one safely use memory space without causing harm to others? |
|||
13 Mar 2007, 15:58 |
|
okasvi 13 Mar 2007, 16:40
Use stack or allocate memory from the heap.
|
|||
13 Mar 2007, 16:40 |
|
Borsuc 17 Mar 2007, 17:27
dvlfrnd wrote: db directive looks static,as it adds itself up to the end of the executable Hint: you can write instructions only with dbs, provided you know the opcodes. That's what i like about assembly: you have freedom. DB puts the specified bytes exactly where you use it. You can imagine instructions are just "macros" that use db to compile the bytes. |
|||
17 Mar 2007, 17:27 |
|
dvlfrnd 18 Mar 2007, 06:52
The_Grey_Beast wrote:
That is very helpful,and a very interesting idea. please correct me if i got it wrong: if "mov ax,34h" was something like "ABCD34" in hex instead of writing Code: ... mov ax,34h ... i could also use Code: ... db ABh ; assuming that i won't need a label db CDh db 34h ... that opens endless possibilities! Thanks again i have a very simple question, suppose i have a code that compiles to 16 bytes, i add this line: buffer db 4 dup (1) the com file becomes 20 bytes if i do this instead: buffer db 4 dup (?) com file's size remains 16 bytes. i'm going to make an uneducated guess,and say,the executable will occupy 20 bytes of memory space, if so, how does this happen? (who allocates that space?) edit - i realized it only happens if .....(?) expression is at the very end of the file Last edited by dvlfrnd on 18 Mar 2007, 15:39; edited 1 time in total |
|||
18 Mar 2007, 06:52 |
|
DOS386 18 Mar 2007, 11:01
Quote: if "mov ax,34h" something like "ABCD34" in hex Wrong. MOV AX,xxxx is $B8 in use16. Operand has 2 bytes. Code: db $B8,$34,0 ; mov ax,$34 Some old assemblers suffered from lack of new instructions so you can see some code using db to code new instructions like CPUID, RDTSC, RDMSR and WRMSR. http://board.flatassembler.net/topic.php?t=6676 _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
18 Mar 2007, 11:01 |
|
dvlfrnd 18 Mar 2007, 15:38
i made those numbers up
why is there a '0' on the tail? thanks |
|||
18 Mar 2007, 15:38 |
|
DOS386 18 Mar 2007, 16:24
Quote: why is there a '0' on the tail Code: db $B8,$12,$FF ; mov ax,$FF12 AX has 16 bits. _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
18 Mar 2007, 16:24 |
|
dvlfrnd 18 Mar 2007, 16:38
NTOSKRNL_VXE wrote:
i see,very clear now,you've also answered one of my future questions thanks NTOSKRNL_VXE |
|||
18 Mar 2007, 16:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.