flat assembler
Message board for the users of flat assembler.
Index
> DOS > My first FASM!!!! Goto page 1, 2 Next |
Author |
|
Dex4u 03 Nov 2006, 17:21
The thing that stands out as very good for a ASM noob, is you comments, this may of come from you coding in other lanuages, well done.
PS: The "126-byte .ZIP viewer" get input from CLI. |
|||
03 Nov 2006, 17:21 |
|
rugxulo 03 Nov 2006, 17:32
int 21h,2 only uses DL, so you can save a byte each time:
Code: BA1300 MOV DX,13 B213 MOV DL,13 Oh, and here's a (quick) example on how to use macros: Code: macro putc char { mov ah,2 mov dl,char int 21h } org 100h putc 'H' putc 'i' putc '!' int 20h In a DOS .COM, the PSP:80h is where the cmdline starts. byte [80h] is the length of the cmdline (excluding the carriage return, aka 0Dh). For example (C.COM is the 126-byte .ZIP viewer): Quote:
The length of the cmdline at byte [80h] would be 12 (aka, 0Ch). (Bah, I'll just keep editing/adding to this one post.) See Ralf Brown's interrupt list (online or download it) for more DOS goodness! Last edited by rugxulo on 03 Nov 2006, 17:46; edited 3 times in total |
|||
03 Nov 2006, 17:32 |
|
eVAPor8 03 Nov 2006, 17:36
Thanks for that Dex! Well, I went mad with comments because:
A. I still remember the pain of writing a tight BBC Model B loop and then coming back to it six months later thinking WTF does that DO??!!! B. I want to use my experiences with FASM to put together some tutorials so that others can get the benefits of my research. (And believe me, just putting THAT little thing together took days of reading!) C. Like I said, I'm an ASM noob, so let's try to start out with good habits and keep them! |
|||
03 Nov 2006, 17:36 |
|
eVAPor8 03 Nov 2006, 17:38
Quote:
Thanks, I'm sure I read DX somewhere, but seeing as only outputs a byte that makes a lot of sense! Thanks! Oh, and BTW, coming from a Basically Visual world *cough*, I'd organise a program like: MainLoop Call Sub1 Call Sub2 Call sub3 If bExit then Exit Sub1 Sub2 Sub3 Do I presume that the macro(s) MUST be defined in the "header" (for want of a better word) before the "main" code in FASM? |
|||
03 Nov 2006, 17:38 |
|
rugxulo 03 Nov 2006, 17:51
Apparently, in my just-now-conducted test, it does need to be defined before used. Shouldn't be that hard to keep track of, IMO. You may even want to put all your macros in an include file to keep them separate from the main code. Oh, and don't forget, you can overload instructions (MOV, XCHG, etc.) with macros in FASM.
FASM documentation online: |
|||
03 Nov 2006, 17:51 |
|
eVAPor8 03 Nov 2006, 18:48
rugxulo,
Thanks for this, I had read the docs before, but there's so much to take in and understand that I never remember where I actually read it! Your post is a great help! Oh and PS, Yeah, I grabbed Ralf's list. It's massive! However, even with the included veiwers I found that: A. It's almost TOO inclusive... Int this with ax that = returns 1234 if SOandSO Virus is loaded. B. No examples. C. It's not very noob-friendly. Mind you, how could it be? I hope that does't come across as a critism. Just putting that lot together in the first place is a massive achievement!! It's just that I like to learn by "getting my hands dirty" rather than reading loads of dry text. I actually kicked off best with Chandler's tutorial, his enthusiasm for asm (well, binary, really) really rubs off and get's you in the mood to "play" and explore the possibilities! I'm sure that as I learn and gain experience, It'll become an invaluable resource! [/i] _________________ Should've ducked faster! |
|||
03 Nov 2006, 18:48 |
|
smiddy 03 Nov 2006, 19:58
Nice coding for your first ASM program, VERY nice indeed. I concur with Dex. Also, you make some good points about the over whelming nature of Ralph's list, however, with some experience you'll see it differently and understand that if there where examples for eveything it would even be that much bigger. Give a look see at Randal Hyde's website for some pointers, etcetera.
|
|||
03 Nov 2006, 19:58 |
|
eVAPor8 03 Nov 2006, 20:37
Thanks, smiddy, I'll take a look once I've macro-ed up this baby!
I just found out something interesting and not in the docs (well, it's bloody obvious TBH, but I hadn't taken account for it - DOH!) I started using the "Byte" converter (I also wrote a word converter) and it failed miserably. OI!!! Stop bleedin' laughing you lot!!! The arg to a macro gets passed over as a word, not a byte, so you can imagine the hilarility when I realised how stupid I am! Actually, as a word address... jeez! I LOVE FASM!!!!!!!!! All that reading AoA, etc... and understanding NOTHING was not in vain! It's all starting to fall into place! Don't you love those "AHA!!!!! moments" FFS I'm just totally in awe of the power this! It's like being "a kid in a candy store" ... Only as a grown up.... with a big fat wallet! If the FASM devel team where girls I'd flippin' kiss 'em all! And the community is so friendly too, none of that "well, if don't understand hard-drive addressing vectors then **** off" rubbish! I think I'm falling in love again. The last time I felt like this was when I saw Defender running on a BBC Model B!!! I mean, it's a Friday night, I'd rather rather be hacking away at ASM than going to the pub and chasing women. ... mind you, THAT could be because of that endless-loop-error "**** off, ugly!!" |
|||
03 Nov 2006, 20:37 |
|
eVAPor8 03 Nov 2006, 21:19
Well, I'm obviously missing something.
My macro'd code looks right, compiles fine, runs without errors but produces incorrect results. Since I've been hacking away at this for around 13 hours, I'm calling it quits. I'm obviously missing something stupid and I'll RTFM in the tomorrow! |
|||
03 Nov 2006, 21:19 |
|
smiddy 03 Nov 2006, 22:14
some times it is a good idea to take a break and get a fresh start after a few winks.
|
|||
03 Nov 2006, 22:14 |
|
2 03 Nov 2006, 22:56
Hey eVAPor8 you're that guy who emailed me! Been reading my tutorials I see. People who read what I write seem to develop an obsession with binary. Well,glad you did it. We need more people like you.
|
|||
03 Nov 2006, 22:56 |
|
2 03 Nov 2006, 23:11
BTW,here's my program that counts every byte value.
Code: org 256 xor ecx,ecx p0: mov bx,8 mov eax,ecx inc ecx p1: dec bx mov edx,eax and dl,1 shr eax,1 or dl,48 mov [b+bx],dl cmp bx,0 ja p1 mov ah,9 mov dx,b int 33 cmp ecx,255 jbe p0 int 32 b db 8 dup 48,13,10,36 |
|||
03 Nov 2006, 23:11 |
|
eVAPor8 04 Nov 2006, 09:46
AAAA---HA!!!!!
So now I know who 2 is ! As it turns out, I've also read a lot of your posts. (I did a lot of lurking before I registered) You've advanced far further in the world of asm than me, but I'll run that code today (If I get time) and try work out what's going on. I don't understand the purpose of that first XOR on ecx! God I HATE being a noob. I'm so used to being the guy that eveyone calls on for help it's embarrasing! .... but discovering this new world is so much FUN!!! I'll have a look at my code this PM (UK) and see if I can correct it, if not, I'll post it up and ask for help! I'm obviously missing something fundamental and critical! All the best, everyone, and thanks for the help! eVAP _________________ Should've ducked faster! |
|||
04 Nov 2006, 09:46 |
|
okasvi 04 Nov 2006, 13:19
eVAPor8 wrote: I don't understand the purpose of that first XOR on ecx! xor ecx, ecx = zero ecx _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
04 Nov 2006, 13:19 |
|
eVAPor8 04 Nov 2006, 18:09
okasvi wrote:
::NOOB ALERT:: That's what I thought, but why not mov ecx, 0h Seems simpler, quicker and more "readable" to me. I'm obviously missing something! I can't imagine that xor use less cycles than mov, so what's the point? What am I missing? _________________ Should've ducked faster! |
|||
04 Nov 2006, 18:09 |
|
Goplat 04 Nov 2006, 18:31
xor ecx,ecx is assembled to 31 C9
mov ecx,0 is assembled to B9 00 00 00 00 They are both one-cycle once decoded, but it is better to use short instructions so the processor does not use as much time reading code from memory. |
|||
04 Nov 2006, 18:31 |
|
eVAPor8 04 Nov 2006, 20:02
Goplat wrote: xor ecx,ecx is assembled to 31 C9 Thanks for this! I have SOOOO much to learn! It's funny, it's both scary as hell, but exciting too! _________________ Should've ducked faster! |
|||
04 Nov 2006, 20:02 |
|
2 04 Nov 2006, 21:34
The other advantage is the program size will be fewer bytes!
That's the big reason I like XOR. Also,notice I did 'or dl,48' instead of 'add dl 48' ? Well,I like to use bitwise operations when possible. I read that they are faster. |
|||
04 Nov 2006, 21:34 |
|
LocoDelAssembly 04 Nov 2006, 21:51
2, are you replacing every ADD with OR? note that it's not the same, it produce the same result only when the 1s bits have a 0 bit in the other operand, otherwise it produces wrong result.
Code: 1010 1010 ADD OR 1010 1010 ===== ===== 10100 01010 Of course it's right in your case because 48 is 110000 and the numbers between 0 and 9 occupy only the four less significant bits. |
|||
04 Nov 2006, 21:51 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.