flat assembler
Message board for the users of flat assembler.
Index
> Main > [16/32/64] Hello, I have a couple of newbie question |
Author |
|
JohnFound 07 Aug 2013, 08:02
A1: IMO, you have to start from 32bit Linux/Windows programming. Then try 64bit Linux/Windows programming. Then (only if you want to create your own OS) learn real mode DOS programming.
A2: I don't know why all beginners start with asking "step-by-step" tutorials. And actually I don't know what meaning they put in this term. Just try to download several simple examples (there are several in FASMW package or Fresh IDE package). Then try to simply compile them and run. This way you will setup your development environment. After that, start to modify some of the examples in order to work a little bit different. Do it for more and more complex examples. Start some small project by yourself. For all this, you probably must have some general programming knowledge. |
|||
07 Aug 2013, 08:02 |
|
dogman 07 Aug 2013, 08:51
Choose what hardware and OS you want to learn on first. The computer you use for most things is the best one to start learning assembly on.
After you choose the environment you can start zoning in on the other details and find tutorials for your chosen platform. |
|||
07 Aug 2013, 08:51 |
|
DOS386 07 Aug 2013, 09:59
> have to start from 16-bit(DOS) programming to 64-bit programming?
NO > Is there a step by step tutorial (or practice) about fasm? The examples ... start with Hello War _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
07 Aug 2013, 09:59 |
|
TightCoderEx 07 Aug 2013, 16:15
JohnFound wrote: A1: IMO, you have to start from 32bit Linux/Windows programming. Then try 64bit Linux/Windows programming. Then (only if you want to create your own OS) learn real mode DOS programming. Sound advice and the reason windows, is that there are a lot of free tools like Ollydbg where you can actually insert code on the fly, run through it and see what is actually happening. First and most important though, is you need understand what the processor can do in the way of instructions. Moving data to and from memory, calculations and branching on conditions are probably a good place to start. Let's hypothetically say you need to know if stack pointer is evenly aligned on a 256 byte boundary and if so, subtract 1024 from it. The ESP value is 418743 or [663b7H] or 1100110001110110111 binary. Code: mov eax, esp and eax, 256 jnz NotEven sub esp, 400h NotEven: nop Tutorials are a great resource, but only after you know what you're looking at. Here is an example of how in a boot loader move sp to top of conventional memory, fill it with -1's and then set the new stack pointer to it. Code: ; Get TOM segment mov ax, 64 ; Point to BIOS DATA AREA mov ds, ax mov ax, [19] ; Get number of 1k pages. Probably 27FH shl ax, 6 ; Convert to segment address mov es, ax Original has a bunch of code in here to read E820 map. ; Build a stack frame of 65k and fill it with -1's so it can be probed for how deep ; BIOS routines or my code penetrates this frame mov cx, 0x1000 mov ax, es sub ax, cx ; Bump segment pointer back 65k mov es, ax xor di, di shl cx, 2 or eax, -1 rep stosd ; Fill 32,768 words with - 1 ; Now we can move previously saved 18 words pointed to by SS:SP to this new frame. cli inc eax mov ax, ss mov ds, ax push es pop ss ; Set new TOS (top of stack) xor sp, sp sti |
|||
07 Aug 2013, 16:15 |
|
neuron 08 Aug 2013, 06:07
To JohnFound.
Thank you. I found 64-bit FASMW in this forum. I'll use that. To dogman. Quote:
OK. I got it. Thanks! To DOS386. Ooops, I think what i need is say hello to this peaceful world. Thank you for your reply. To TightCoderEx. Sorry, I definitely dont know what are your codes saying. And your link is not accessible in china mainland. |
|||
08 Aug 2013, 06:07 |
|
whakamaru 30 Dec 2013, 21:23
In fasm-for-dos, there is an example USEDPMI.ASM. If I replace the lines between start: and done: with my solution to Euler #5, it compiles, runs and displays the correct answer.
When I put the same lines after the directives... format MZ entry main:start segment main use32 start: nop... etc ...... it compiles OK but doesn't run. I get an error message from "16-bit MS-DOS sub-system" I assume (at the risk of being half wrong?) that the directives are incorrect. I have studied the documentation and all the examples, but unfortunately there are no examples specifically about 32-bit stand-alone programs. What might the correct directives be? Many Euler problems involve HUGE numbers. It is hard trying to solve in 16-bit, and since all modern laptops now have 64-bit CPUs I would like to have a go at 32 or 64-bit solutions.ie, for #401 ! So, what would the directives for a straightforward, relatively short, 64-bit listing that does number crunching and then displays the (correct) answer be? I have also downloaded FASM for Windows and put the #5 lines into the PEDEMO.ASM example, and much to my surprise it compiled, ran and gave me the correct answer. So maybe a similar insertion into PE64DEMO.ASM might work? _________________ watch this space |
|||
30 Dec 2013, 21:23 |
|
revolution 31 Dec 2013, 00:15
You can't use "use32" in a 16-bit program unless you switch the CPU to 32-bit mode before executing the 32-bit portion of the code.
|
|||
31 Dec 2013, 00:15 |
|
DOS386 01 Jan 2014, 09:18
> but unfortunately there are no examples specifically about 32-bit stand-alone programs.
Get the Win32 version of FASM. 16-bit DOS alone cannot run "32-bit stand-alone programs". See also: http://board.flatassembler.net/topic.php?t=6633 and the FAQ http://board.flatassembler.net/topic.php?t=9473 E. 13. "Can I develop 32-bit apps for a 16-bit DOS ?" and the other FAQ's ... 99.99% of possible problems already covered |
|||
01 Jan 2014, 09:18 |
|
sid123 07 Jan 2014, 09:13
Hi,
Firstly welcome . Answer 1: 32 bit is recommended. However before starting with anything I'd tell you some basic stuff. 1. In assembly unlike other languages things are controlled by some variables that can be understood by the CPU, technically called registers. There are some general purpose registers colloquially GPR's means you can use them for almost anything. They are : AX (accumulator) BX (base) CX (counter) DX (data) SI (source index) DI (destination) SP (stack pointer) BP (stack base pointer) Don't worry about what's in those brackets, but you can use them for almost anything like storing values etc. These are 16 bit registers and can holds max value of 65535 (64KB). To convert them to 32 bit we simply add an E, ex : EAX,EBX,ECX these can hold up to 2,147,483,647. And to 64 bit you add an R like RAX,RBX,RCX etc. 2. Some instructions. There are some simple instructions that can be used in assembly language, Some really common ones are: MOV, ADD, SUB, DIV, MUL, LOOP, INT, CALL, JMP, JC, STI, CLI, RET, IRET, RETF, PUSHA, POPA, PUSH, POP, PUSHF, POPF. Check out on the internet or the FASM Manuals what these mean, they aren't that complex. 3. Get familiar with hexadecimal and binary systems, Basically hexadecimal system is base 16 as opposed to the normal base 10 system. In normal counting numbers are: 1 2 3 4 5 6 7 8 9 10 In hexadecimal there are 16 instead of ten. 1 2 3 4 5 6 7 8 9 A B C D E A simple conversion would be: 10 = 0xA Note: We add a 0x in front of a hexadecimal number to denote that it has a hexadecimal value, another notation is adding a 'h' add then end like A000h, FASM accepts both notations so you can use whatever you want. 4. Finally I'd say the main difference between 16/32/64 bit is the way you access memory, in 16 bit you can't access more than 64KB at a time unless you mess with ugly segment registers which are a big nightmare and even using that you will only be able to access 1MB, so writing in 16 bit mode means that you must write small and efficient code which I at least can't write. In 32 bit I think you can access up to 4GB of memory, if you want to access more then there is something called PAE, which isn't as horrible as segment registers, then in 64 bit theoretically you can access up to...... well 4PB (THEORETICALLY!) Answer to question 2 Tutorial? There are a lot of examples in the FASM/EXAMPLES directory that comes with FASM, they show simple concepts like drawing message boxes, text editing, OpenGL (not sure about this one but I think I saw it). Cheers, sid123 |
|||
07 Jan 2014, 09:13 |
|
DOS386 08 Jan 2014, 08:54
In 32-bit code you should use 32-bit registers, 16-bit (AX,BP,...) is mostly possible but inefficient (8-bit is OK), 64-bit (RAX) is NOT possible.
|
|||
08 Jan 2014, 08:54 |
|
sid123 08 Jan 2014, 09:26
Yes using 32 bit registers in 16 bit is also possible but I guess there is a limit prefix (66h?) that's added. 16 bit code in 32 bit is possible through Virtual 8086 Mode, In 64 bit this is not possible unless you use an emulator.
|
|||
08 Jan 2014, 09:26 |
|
whakamaru 13 Jan 2014, 21:54
thanks...especially DOS386... such a lot to learn... much on these pages...I'll get there... maybe...
|
|||
13 Jan 2014, 21:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.