flat assembler
Message board for the users of flat assembler.
Index
> Windows > Learning Assembly Goto page Previous 1, 2 |
Author |
|
Trinitek 01 Apr 2017, 00:55
|
|||
01 Apr 2017, 00:55 |
|
rugxulo 01 Apr 2017, 01:19
C0deHer3tic wrote: I looked in the Pcasm book and could not find the movsx or movzx command. However I found this ... I already pointed you to old NASM 0.98.39's docs, which has a fairly good basic instruction list. It's certainly simpler than Intel's or AMD's docs. Code: Archive: nasm-0.98.39-xdoc.zip Length Date Time Name --------- ---------- ----- ---- 565153 01/15/2005 16:21 doc/nasmdoc.txt --------- ------- 565153 1 file Quote:
BTW, I also think (aforementioned) Ray Seyfarth's EBE (free on SF.net) would help you debug such programs (see the tutorial). Maybe everyone here disagrees (or has a better suggestion, OllyDbg?), but I really think it would be more helpful than trying to understand manually. |
|||
01 Apr 2017, 01:19 |
|
Trinitek 01 Apr 2017, 01:34
|
|||
01 Apr 2017, 01:34 |
|
Furs 01 Apr 2017, 11:11
Yeah, too bad x64dbg is so stupidly bloated compared to OllyDbg. I mean, orders of magnitude more bloated... (but OllyDbg 64 seems to be dead, sigh)
|
|||
01 Apr 2017, 11:11 |
|
Tomasz Grysztar 01 Apr 2017, 11:58
Furs wrote: Yeah, too bad x64dbg is so stupidly bloated compared to OllyDbg. I mean, orders of magnitude more bloated... (but OllyDbg 64 seems to be dead, sigh) |
|||
01 Apr 2017, 11:58 |
|
Furs 01 Apr 2017, 15:13
Oh wow very interesting, thanks
|
|||
01 Apr 2017, 15:13 |
|
Furs 02 Apr 2017, 11:30
Show your full (modified) code? The cmp is indeed useless but you probably messed up something else.
BTW "push" is very easy to understand. In C, when you put something in an array via a pointer, you do something like this: Code: *ptr++ = blah; Code: *(--esp) = blah; // same as "push blah" So it simply decrements esp by 4, then puts the value in the "push". Pop does the opposite: loads the value at "esp", and then increments it: Code: // pop blah blah = *esp; esp++; |
|||
02 Apr 2017, 11:30 |
|
C0deHer3tic 02 Apr 2017, 19:59
Furs wrote: Show your full (modified) code? The cmp is indeed useless but you probably messed up something else. Code: format PE console entry main include 'macro/import32.inc' section '.data' data readable writeable msg3 db "%d",1010b,0 msg db "Enter your name: ",0 section '.code' code readable executable main: mov ebx, 8 loop_1: dec ebx push ebx push msg3 call [printf]; Still using printf. Have not figured out the other one. ;cmp ebx, 0 jnz loop_1 push msg call [printf] pop ebx mov dword [esp],0 push 0 call [exit] section '.idata' import data readable library msvcrt,'msvcrt.dll' import msvcrt,\ printf,'printf',\ exit,'exit' This doesn't print out the numbers as it goes. It just does: Code: 7 Enter your name: _________________ - Just because something is taught one way, does not mean there is not a different way, possibly more efficient. - |
|||
02 Apr 2017, 19:59 |
|
shutdownall 02 Apr 2017, 21:47
C0deHer3tic wrote: What is the assembly equivalent of printf? Funny question for assembly programmers. I will try to keep it philosophic. Printf is an equivalent of maybe a few hundred or more assembly instructions in a special composition. Assembly instruction is the smallest part of any task. If you read a book, than the whole book can be imagined as an application while the chapters are functions inside the application and words may be treated as c-functions while the letters contained of any word are assembly instructions building the c-function. |
|||
02 Apr 2017, 21:47 |
|
C0deHer3tic 02 Apr 2017, 22:19
shutdownall wrote:
Thank you for explaining that. I am new to assembly, and therefore I have no idea where to start. I tried to start off like learning C, however I see that I needed to know other things before that. I am a noob to all of this, so my questions will seem ridiculous I am sure. _________________ - Just because something is taught one way, does not mean there is not a different way, possibly more efficient. - |
|||
02 Apr 2017, 22:19 |
|
shutdownall 02 Apr 2017, 22:39
The main thing is, that there is no equivalent of assembly instructions to c-functions like printf because assembly instructions are a part of these functions. There can not be an equivalent except many instructions carefully composed to a function similar behaving as the c-function you desire.
Or talking in chemistry: An assembly instruction can be imagined as an element / atom and you are trying to find an equivalent of a complex molecule with just a simple atom. Best start would be tutorials in the internet for assembly programming x86. A more easy step is to program WIN applications using the WIN functions, which can be called simply using register values and pointers and using data structures. I think this is the fastest way keeping motivation while showing fast success of your work. Try out the Hello World example and then get deeper step-by-step. There are many examples provided with FASM as well which can be compiled fast and investigated after in detail. |
|||
02 Apr 2017, 22:39 |
|
zhak 02 Apr 2017, 23:30
I've been visiting this topic from time to time and frankly speaking I don't understand all that "I am new to assembly, and therefore I have no idea where to start" stuff. You have all the Internet at your fingertips. Why don't you find a book and go through it step by step learning registers, then addressing, then how to call functions, and so on and so forth? I remember when I first started to learn assembly, I didn't have Internet connection at all. I bought a book at the store and slowly read it page by page, trying understand, trying to assemble examples inside.
Debugger is a great thing -- you don't even need full executable to check what this or that instruction does. You can just type instructions and execute step-by-step and see what happens. A very convenient thing I didn't have in the beginning. Well, soon I had debug.exe, but that's no comparison what you've got now (mentioned here xdbg or olly)... I don't know... BTW I still have that book https://drive.google.com/file/d/1sWaYD0Zb_g4RvubiWoeRhMaf77VO-YNAWQ/view[/url] |
|||
02 Apr 2017, 23:30 |
|
revolution 03 Apr 2017, 00:33
C0deHer3tic wrote: This doesn't print out the numbers as it goes. It just does: |
|||
03 Apr 2017, 00:33 |
|
Trinitek 03 Apr 2017, 00:35
C0deHer3tic wrote: I am new to assembly, and therefore I have no idea where to start. I tried to start off like learning C, however I see that I needed to know other things before that. I am a noob to all of this, so my questions will seem ridiculous I am sure. I say you should refocus on an end goal, not just "learning assembly." Can you think of a particular project you want to tackle as an exercise? Perhaps something involving a simple algorithm, even involving floating point if that's your fancy. (That would be a good entry to SSE or x87) Or maybe you want to take a look at stack operations first? |
|||
03 Apr 2017, 00:35 |
|
C0deHer3tic 03 Apr 2017, 00:38
shutdownall wrote: Best start would be tutorials in the internet for assembly programming x86. I tried starting with the x86 programming. It led me down roads where the code would not run on my computer, unless usinging DosBox, or emulators. Trust me, I have looked. That does not mean it is not there, I just have not found it, and so I came to here since I did not find a beginners tutorial for FASM. C is coded the same way in almost every compiler, except for some (Turbo C). I have masm32, and I have FASM, as well as nasm. 1. The tutorial for masm32 was GUI, and I wanted to stay clear from that at the moment. 2. The nasm tutorial had two problems: A. It could not run in the windows 8 system, when compiled. B. The other tutorial was for Linux. Thus it used Linux interrupts. 3. FASM was my next go to. And I understand you all must think I am either ignorant or trolling, but I just have been all over the place. I find a tutorial I think will teach me something, and then I am back to square one. Why would I want to learn programming for code that doesn't even run in my environment? If there is a good reason, I am open to hear it. Quote: A more easy step is to program WIN applications using the WIN functions, which can be called simply using register values and pointers and using data structures. I think this is the fastest way keeping motivation while showing fast success of your work. What do you mean by WIN applications? Are you talking about windows applications? If so, what do you mean by using the WIN functions? Quote: Try out the Hello World example and then get deeper step-by-step. There are many examples provided with FASM as well which can be compiled fast and investigated after in detail. I understand how to print out "Hello world". As far as get deeper and deeper? That is my whole goal here. Let me link you to a pdf on learning C. This is the type of learning I am looking for. https://kldp.org/files/c+in+21+days.pdf And at this point, I would pay for a class to learn assembly. You all are helping me, and I appreciate it. @zhak, With all due respect, that book you showed is in Russian and I don't understand Russian. But I hear you. I have tried to read several books. ---------------------------------------------------------------------------------- 1.PC Assembly Language - Paul A. Carter. 2. Assembly Language: Step-by-Step - Jeff Duntemann 3. The Art of Assembly Language - Unknown 4. Programming from the Ground Up - Johnathan Barlett (Edited by Dominick Bruno, Jr.) 5. Windows Assembly Programming Tutorial - Jeff Huang ---------------------------------------------------------------------------------- I could not follow along from the simple problem of not being able to compile and run their code. It would either crash, not execute, or spit out errors. _________________ - Just because something is taught one way, does not mean there is not a different way, possibly more efficient. - |
|||
03 Apr 2017, 00:38 |
|
C0deHer3tic 03 Apr 2017, 00:50
@Trinitek
Okay a goal would make a calculator (text based) Here is what I need to learn. 1. Output (I know that with printf) 2. Input (I understand this with scanf) 3. Math functions (add, sub, div, etc which I understand) 4. I need a main loop which allows me to run a menu: Code: MENU -------- 1. Add 2. Sub etc... Therefore I can add, and then get the result and it will take me back to the menu. 5. Also a big help to me, and a code shortcut in C I learned for making lines was this simple command: Code: void lines(int amount) { int i; for(i=0;i!=amount;i++) printf("\n"); return; } ........... So in the code I could do this printf("Hello World!"); lines(2); I tried to integrate this function in my assembly program, but I don't know how to pass a variable to a function. I am not even sure how functions work in assembly. 6. Each math operation I would like it to be a function: int ADD(int y, int x); int SUB(int y, int x); etc..... That is a good place to start, I think. I did the same in C. _________________ - Just because something is taught one way, does not mean there is not a different way, possibly more efficient. - |
|||
03 Apr 2017, 00:50 |
|
C0deHer3tic 03 Apr 2017, 01:02
Here is the program so far. Only adds right now.
Code: ; Adds two numbers and prints results ;------------------------------------------------ format PE console entry main ;IMPORTS ;------------------------------------------------ include 'win32a.inc' section '.idata' import data readable library kernel32, "kernel32.dll", \ msvcrt, "msvcrt.dll" import kernel32, \ ExitProcess, "ExitProcess" import msvcrt, \ printf, "printf", \ scanf, "scanf" ;------------------------------------------------ ;DATA ;------------------------------------------------ section 'data' data readable writeable prompt1 db "Please enter a number:",9h,0 prompt2 db "Enter next number:",9h,0 result db "The number %d added to %d = %d",0 newline db "",1010b,0 input db "%d",0 num1 dd ? num2 dd ? ;------------------------------------------------- ;[Main Program] ;------------------------------------------------ section '.code' code executable ;[PROGRAM START] ;------------------------------------------------ main: ;[Prints Prompt1 to console] ;------------------------------------------------ push prompt1 call [printf] ;------------------------------------------------ ;[Get input] ;------------------------------------------------ push num1 push input call [scanf] ;------------------------------------------------ ;[Newline] ;------------------------------------------------ push newline call [printf] ;------------------------------------------------ ;[Prints Prompt2 to console] ;------------------------------------------------ push prompt2 call [printf] ;------------------------------------------------ ;[Get input2] ;------------------------------------------------ push num2 push input call [scanf] ;------------------------------------------------ ;[result printed out] ;------------------------------------------------ mov ebx, dword[num1] add ebx, dword[num2] push ebx push dword [num2] push dword[num1] push result call [printf] ;------------------------------------------------ ;[Clean up] ;------------------------------------------------ add esp, 4*4 push 0 ;------------------------------------------------ ;[Kill program] ;------------------------------------------------ call [ExitProcess] ;------------------------------------------------ _________________ - Just because something is taught one way, does not mean there is not a different way, possibly more efficient. - |
|||
03 Apr 2017, 01:02 |
|
rugxulo 03 Apr 2017, 06:44
C0deHer3tic wrote: Why would I want to learn programming for code that doesn't even run in my environment? If there is a good reason, I am open to hear it. I have started a new thread (in "Programming Language Design" subforum) as a weak means to address this: why learn code that doesn't run? |
|||
03 Apr 2017, 06:44 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.