Here is a nice "cheat sheet" for getting "up and running" quickly:
Ancient Dragon commented: great post and links +10
~s.o.s~ commented: Nice one. +20
Here is a nice "cheat sheet" for getting "up and running" quickly:
Frank recently posted the following code in the alt.lang.asm newsgroup.
;---------------------------------
; nasm -f bin -o hwnoint.com hwnoint.asm
org 100h
push word 0B800h ; segment of video memory
pop es ; (because stosw uses es:di)
mov di, (10 * 80 + 30) * 2 ; offset into screen
; (row * width + column) * 2 bytes/character
mov si, msg ; offset of our string
mov ah, 0B0h ; color (blinking black on cyan)
top:
lodsb ; get byte from [ds:si] into al
; and increment si for next one
or al, al ; this doesn't change al, but sets
jz depart ; the flags - if zero, we're done
stosw ; stores ax (char & color) to [es:si]
; and add 2 to di for next one
jmp short top ; do more
depart:
ret ; return to dos (or other caller)
msg db " Look, Ma! No ints! ",0 ; note 0, not '$', terminated
; '$' is just for int 21h/9
;------------------------------------
Nathan.
Download "disasm.zip" from the Files section of AoAProgramming:
http://groups.yahoo.com/group/aoaprogramming/
It is a good place to start on coding a modern-day disassembler/debugger.
Nathan.
http://del.icio.us/Evenbit
Well yea, So I try to do like
mov ah,01h int 16h
Shouldn't that let the user in put whatever he/she wants?
That is a DOS system call... it will only work on Linux if you are running a DOS emulator. Nothing wrong with that, but since you are using Linux, why not run your programs natively? Some Linux ASM resources are here:
http://asm.sourceforge.net/resources.html#docs
http://members.save-net.com/jko@save-net.com/asm/
A "Hello, World!" for Linux looks like this:
; nasm -f elf hello.asm
; ld -o hello hello.o
global _start
section .data
hello db "Hello, World!", 10
length equ $-hello
section .text
_start:
mov eax, 4 ; write to file
mov ebx, 1 ; STDOUT handle
mov ecx, hello ; our message
mov edx, length ; size of message
int 80h ; execute the syscall
xor ebx, ebx ; send 0 as 'exit code'
mov eax, 1 ; terminate process
int 80h ; execute the syscall
You have several "int 0x21" calls in your code. These are DOS calls:
http://www.ctyme.com/intr/int-21.htm
Since DOS is not loaded (indeed, you are writing your own OS), then you cannot use these functions. You must restrict yourself to just the BIOS calls.
Nathan.
You can find tutorials and examples here:
The Operating System Resource Center
http://www.nondot.org/sabre/os/articles
OS FAQ Wiki
http://www.osdev.org/osfaq2/
Nathan.
http://sourceforge.net/project/showfiles.php?group_id=165727
Version 2.3 of the StdLib is now on SourceForge.
- Improvements: Linux support is now more complete.
- Includes: Automated Test Suite
The intention of this project is to support users of Randall Hyde's HLA (High Level Assembly) language who wish to maintain, extend, or evolve the HLA Standard Library. http://webster.cs.ucr.edu/AsmTools/HLA/index.html
http://webster.cs.ucr.edu/AsmTools/HLA/stdlib2/index.html
Nathan.
[[ re-posted from the DesktopLinuxAsm mailing list ]]
http://groups.yahoo.com/group/DesktopLinuxAsm/
<< Here is a puzzle for assembler guru's and anyone
who needs a diversion.
Bill Gates has spent the last year working on a virus to
destroy Linux. To complete his virus he needs the constant
of -4 in eax. His virus hides in the ELF header and at this
point he only has 2 bytes of program space left. All his
general registers are zero at this point.
How does Bill generate -4 in two bytes of code?
Warning, Bill Gates is devious, cunning, and so is the
solution. If anyone can solve this they will suffer exposue
on DesktopLinuxAsm web page and envy from everyone
who claimed it could not be done.
all the best, jeff >>
Nathan.
http://del.icio.us/Evenbit
----
http://sourceforge.net/project/showfiles.php?group_id=165727
Version 2.2 of the StdLib is now on SourceForge.
- Improvements: increases OS independance, performance, and design consistency. Accessible from other assemblers and other languages.
- Includes: Automated Test Suite
The intention of this project is to support users of Randall Hyde's HLA (High Level Assembly) language who wish to maintain, extend, or evolve the HLA Standard Library. http://webster.cs.ucr.edu/AsmTools/HLA/index.html
http://webster.cs.ucr.edu/AsmTools/HLA/stdlib2/index.html
Nathan.
http://del.icio.us/Evenbit/x86
----
ASSEMBLY LANGUAGE information, tools, forums, and other links available at:
http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.asm.x86.html
i have installed nasm in ubuntu in linux but dont know how to and where to write code of assembly language and run my code please give me information as soon as possible.
Using the menu at the top of the screen, go to Applications > Accessories and select "Text Editor" -- when it appears, type this there:
global _start
section .data
hello db "Hello, World!", 10
length equ $-hello
section .text
_start:
mov eax, 4 ; write to file
mov ebx, 1 ; STDOUT handle
mov ecx, hello ; our message
mov edx, length ; size of message
int 80h ; execute the syscall
xor ebx, ebx ; send 0 as 'exit code'
mov eax, 1 ; terminate process
int 80h ; execute the syscall
Save that as "helloworld.asm" into your home directory (the one with *your* name on it).
Then, go back to Applications > Accessories and select "Terminal" and type the following:
nasm -f elf helloworld.asm
ld -o helloworld helloworld.o
./helloworld
You can always type "man nasm" for more help.
You simply forgot to store the result to the final array.
loopi:
MOV AX, [SI]
MOV BX, [DI]
MOV DX, [SP]
SUB AX , BX
MOV DX, AX
MOV [SP], DX <<< add this line
INC SI
INC DI
INC SP ;this is wrong, what should i write here?
LOOP loopi
Nathan.
Adding this link to a blog which starts an interesting tutorial using NASM on a Linux platform.
Nathan.
< knock, knock > Hello? Anyone home?? Is there a sequal on the way???
Nathan.
There seems to be a lot of interest in 16 bit code in this forum , which leads me to believe there are a lot of educational institutions teaching this. My question would be WHY?
"If it isn't broke, don't fix it!" ;-)
Nathan.
I don't really insist on learning anything... That's just the tutorial that I found.
So, if it's better to learn 32 bit, I certainly would rather learn that. :)
Do you know of any online tutorials that teach the code that Masm works with (32 bit)?
There are some here:
http://www.asmcommunity.net/board/index.php?action=wiki
And a neat one here:
http://www.deinmeister.de/wasmtute.htm
You can download a PDF here:
http://www.acm.uiuc.edu/sigwin/old/workshops/
And a CHM format one here:
http://www.madwizard.org/view.php?page=tutorials.contents
Nathan.
If you insist on learning the obsolete DOS-style 16-bit code, then you need to get a 16-bit linker. One is available ( Lnk563.exe ) here:
http://website.masm32.com/microsft.htm
Nathan.
Since Mac OS X is based on BSD, you will have better luck making BSD-style calls instead of those Linux syscalls. BSD looks for the function parameters on the stack instead of in the registers. Here are some tutorials:
http://user.nj.net/~tms/hello.html
http://www.int80h.org/bsdasm/
Nathan.
I'm writing a compiler, but if I want it to be on more than one platform, it seems I have to learn every assembly language for the different platforms. I've seen a number of languages which try to be 'portable assembly languages' such as Linolium and C--, but they all seem to be incomplete or abandoned.
Yes, people try these ideas but they tend to go nowhere because this approach works against itself. Assembly is the language that the CPU understands ... therefore it is a highly hardware dependent language and this is where all the benefits come from -- take away this "close bond with the hardware" and you will loose all of the benefits. This is why C is still widely used today -- it is as close as one can get to ASM and still be portable.
Is there any such language which can be used as a compiler back-end language?
Actually, the Java byte-code runs on a virtual machine (VM) and so does the MSIL for .NET (and mono) -- of course, this is managed code (runs in a "sandbox") but either of these could function as a 'portable assembly-like language' to be used as a compiler back-end.
Nathan.
Your best bet would probably be to look at existing (hopefully *working*) example code which you can find stored away all over the Internet. Here are some links to get you started:
http://www.programmersheaven.com/zone5/mh1.htm
ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/
http://www.textfiles.com/programming/
http://www.nondot.org/sabre/os/articles/CommunicationDevices/
Nathan.
Do we have a program which can convert C or C++ to assembly ?
Please give me a link for help me
Tanks a lot
Yes, these programs are called compilers. You can find a nice list of C and/or C++ compilers here:
http://www.thefreecountry.com/compilers/cpp.shtml
Study the command-line options... most have a switch or two to allow you to specify the assembly language output.
As you elude to WinXP, I'll assume you are doing a windows application and as such you must include kernel32.lib and call one of the text emitting functions DrawText, TextOut or ExTextOut. For example DrawText requires 5 parameters as follows
1. Your programs window device context
2. Long pointer to string (in your case Command)
3. Length of string
4. Pointer to bounding rectangle (see Rect Structure)
5. Flags, how you want the text to be displayed within defined rectangle.
That's the procedure for displaying "text" in a window. Heck, it is even simpler than that -- just call MessageBox. Sadly, this was not the original poster's question.
Nathan.
I would like to know what is wrong with this code:
[BITS 32] ; Windows XP SP2 32-bit section .text global _main _main: push Command mov eax, 0xAABBCCDD ; address of system() call eax Command: db "echo whatever"
The "echo" command is implemented by "CMD.EXE" [ "COMMAND.EXE" on Win95/98 ] so you will have to launch "CMD.EXE" by starting another process. You can use either ShellExecute or CreateProcess to do this. You will want to change your string to "cmd.exe echo whatever" or you could also use "start cmd.exe echo whatever". Here is Microsoft documentation:
ShellExecute
http://msdn2.microsoft.com/en-us/library/ms647732.aspx
CreateProcess
http://msdn2.microsoft.com/en-US/library/ms682425.aspx
Nathan.
Im not asking for code or anything, just an idea. I tried manually moving the first letter into the last letter of the new string with:
reverse:
mov ah,theword[bx] ;read the letter
dec bx ;decrease the read pointer
mov wordbw[di], ah ;write the letter
inc di ;increase the write pointer
cmp bx,0 ;check if the original word point is now at 0
JE print ;if it is then the loop can exit
loop reverse ;if not, then back to the beginning of the loop
end quote.
Try something like this:
mov al, 0
push al
move2stack:
mov al, theword[bx]
push al
inc bx
cmp al, 0
jne move2stack
pop al
xor bx, bx
move2mem:
pop al
mov wordbw[bx], al
inc bx
cmp al, 0
jne move2mem
Nathan.
Hi,
I am having a problem while accessing Assemblies inside my program.
I have two asssemblies having same name but different version. Both contents the same method, but the method have different functionality.
Now I want to access both assemblies in turn both method for different functionality inside a single function . Please Provide some hints or if possible code to do it.
Thanks
Simply rename one of the methods.
Having good reading material handy is always helpful:
http://www.drpaulcarter.com/pcasm/
http://webster.cs.ucr.edu/AoA/index.html
http://savannah.nongnu.org/projects/pgubook/
If that doesn't help, you should paste your problematic assembly code here and maybe one of us can spot the error.
Nathan.
Between NASM and FASM which one would you pick?
And I pretty new to ASM but I think the Intel style looks better so I think that rules GNU out unless they have a Intel version syntax.
A good reason to pick NASM would be that you have at your disposal a great deal of resources (books, tutorials, example code, current users) to help you along the way. Of course, FASM was heavily enfluenced by NASM, so much of the material can be converted to something FASM can digest. However, such a task is easier accomplish by seasoned programmers -- thus it isn't recommended for a beginner.
In the end, it just comes down to personal preference.
Nathan.
Just for fun, I wrote up a quick tutorial for basic assembly. At present, it's only in the form of a PDF document, but I'll eventually get around to adding it to my website.
To encourage you to do more, here is a little more feedback on your tutorial. For these, I will reference section headings and paragraphs --
Prerequisites:
o Well, you know what they say about assumptions. ;)
Notes about the Tutorial
o P2 - "inconjunction"
o Maybe give a link where they can get GCC?
Basic Components (.data section)
o In P3, the sentence about dq and dt -- do you need it?
o Code comments are inconsistent.
o Leaves a question open of how many bytes are allocated.
BETTER:
myvar: ; Declare a variable
myvar: db ; Initialize the variable
myvar: db ‘Hello, world!’,10,0 ; Allocate 15 bytes (this is a C-style string)
Registers
o P2 - "The four registers break down" which four??
The rest of the document gets better, so I'll stop here.
Nathan.
Every version of MS-Windows is shipped with a free assembly language debugger. It's located in the c:\windows directory (or wherever you installed the operating system), and named debug.exe
This is a brief tutorial how to use it.
I'm adding this two to the list of DEBUG tutorials:
http://www.armory.com/~rstevew/Public/Tutor/Debug/debug-manual.html
http://www.geocities.com/thestarman3/asm/debug/debug2.htm
Nathan.
I do not know the way of checking ,
I mean using of T , R ..... in Debugyou got my point!
I want to Know steps ,
for example :
if our programe about adding two No. , i want to make sure that variable "sum" contain the result of adding .
Well, Ancient Dragon gave a link to this short DEBUG tutorial:
http://users.easystreet.com/jkirwan/new/x86lrn03.html
A quick Google search netted a couple more nice ones:
http://www.armory.com/~rstevew/Public/Tutor/Debug/debug-manual.html
http://www.geocities.com/thestarman3/asm/debug/debug2.htm
Textpad 4.6.2
You really should try something better. Check out the resources listed in this sticky thread:
http://www.daniweb.com/techtalkforums/thread67183.html
Nathan.
Just for fun, I wrote up a quick tutorial for basic assembly. At present, it's only in the form of a PDF document, but I'll eventually get around to adding it to my website.
Just a couple of quick notes:
o You might want to talk about the structure of the CPU first before giving ANY code.
o You might want to describe an intruction before you use it in a code listing.
o What about comments beside the code?
o Remove sentences that don't contribute to learning assembly.
o Maybe split this into about 3 sections/chapters?
A really good start!
Nathan.
Hmm i found the answer ...
Yep, HLA's type-checking can cause a little angst until you get comfortable with it.
Nathan.
I've heard that executables may be compressed (unless encrypted) with certain routins. Who could tell me a file expander tool to remove the compression envelope from exe's?
Probably the most popular tool is UPX:
A Google search for "exec packer" might net you more...
Nathan.
Hi all,
I am after a instruction set with limited or no floating-point instructions. Why I want this is to get a compiler of this certain architecture and compile code (one with floating-point and the other without). With the resulting assembly I wanted to compare the two and do some analysis.So what I need exactly is a compiler with access to compiling with/without floating-point.
Any help is welcome, thanks in advance.
The old compilers for 16-bit DOS and 16-bit Windows (that would be Windows versions 3.0, 3.1, and 3.11, etc.) provided such functionality. You can still download compilers like that. Two that I know of:
GFA BASIC
http://en.wikipedia.org/wiki/GFA_BASIC
Digital Mars C/C++
Nathan.
Hello everyone, Im new in assembly language. I would like to ask your help to teach me how to convert the below C language into tasm language. thank you very much.
#include <stdio.h>
#include <dos.h>
main()
{
unsigned int year;
unsigned char month;
unsigned char day;
union REGS regin,regout;clrscr();
regin.h.ah=0x2A;
/* intdos(®in,®out);*/ int86(0x21,®in,®out);
day=regout.h.dh;
year=regout.x.cx;
printf("Today's date is: %d-%d-%d\n",month,day,year);
return(0);
}
Simple:
mov ah, 0x2A
int 0x21
You should find the 'day' in DH and the 'year' in CX.
Nathan.
well i think you can't use much C lang stuff with tasm.. the reason is that it uses DOS and you know that it can only program 16 bit stuff not 32-bit.. so i got the same problem but just upgraded to masm.. there's inbuilt libraries available in that. or you can work with nasm/fasm.. try any.. have a nice day! good luck :)
Nonsense! First, there are C compilers available for DOS. Second, TASM does support 32-bit code.
Nathan.
I need help as to how 2 change machine codes 2 binaries or hex like mov to mayb 101011111, yeah, u know like own compiler
Not sure what you are wanting to do, but here are some resources to check out. First, take a look at Randall Hyde's discussion of a "Y86" simplified CPU --
some background:
3.12 Bit Fields and Packed Data
http://webster.cs.ucr.edu/AoA/Windows/HTML/DataRepresentationa7.html#999885
the "Y86" encoding explained:
5.3 Basic Instruction Design Goals
http://webster.cs.ucr.edu/AoA/Windows/HTML/ISA.html#1013428
Then look at Daniel Sterling's SML: Simple Machine Language
http://www.lost-habit.com/sml/
You also might want to do some basic research into compiler construction. Here are a few usefull links:
http://www.faqs.org/faqs/compilers/faq/
http://www.freetechbooks.com/viewforum.php?f=14
http://cs.wwc.edu/~aabyan/464/Book/
Nathan.
I appreciate everyone's effort in making this list. Here are a few more:
Ralf Brown's Interrupt List (HTML version)
Jeremy Gordon's Go Tools
OllyDbg A great Windows debugger by Oleh Yuschuk.
Pelle's Macro Assembler (forum for news and latest version links)
It is about time we start building a Sticky in this forum listing some resources so the newbies will have an easier time finding the information they need. I will start with these valuable links:
x86 Assembly Language FAQs
Wikipedia: Assembly Language
Wikipedia: List of assemblers
Links at Webster
MASM related info and links
Linux assembly links
Hello everyone. I read a couple of tutorials on x86 assembly a while ago. It was made clear in these that certain instructions need to be included at the end of a program to make it close properly. However, there was some inconsistency about how a program should be terminated. Could anyone tell me how a process should be closed on a win32 system and is this proceedure OS specific? Thanks.
Steven.
There are three (3) different means of process termination on a Win32 system and all three are "proper" or valid.
The first (most common) method is: any thread in the process can make a call to the ExitProcess function.
The second (should be avoided) method is that another process (e.g. application, process explorer) makes a call to the Terminate Process function passing as a parameter the process handle for the application being terminated.
The third (rare) method is when all the threads in a process simply die on their own {e.g. they all call the ExitThread function} leaving the process with no reason to exist so the OS kills the process. NOTE: Since every process has at least one thread....if you do not indulge in any multithreading code {i.e. make calls to CreateThread}, then ExitThread is synonimous with ExitProcess.
Since it requires a 100% rewrite of assembly language programs to port from one platform (e.g. 80x88) to another (e.g. AIX Unix), assembly language, by definition, is unportable.
Quoting myself here: "Hate to be pedantic, but actually, it *is* portable! As long as you stay on the same Arch anyway." -you can see that I was talking about portability on the same hardware.
What are the characteristics that allow a language to be portable? Packaging has a lot to do with it. If you write a Java program, it is cross-platform *only* to the extent that a Java run-time environment (VM, JIT-engine, etc.) is available on the target platform.
If we confine our discussion to x86 hardware, we have a few OSs to contend with (Windows, Linux, BSD, OS X, DOS, etc.), but we can see that we _do not_ need to alter any of our core application code when transitioning from one OS to the other. This is because it is the CPU which executes the Machine Language instructions -- not the Operating System. All that is needed is a library of wrapper functions (just like C and C++ have their libs which do the same thing) to isolate the calls to operating system services.
For example: One can write a program (as long as you restrict yourself to command-line "filter-type" programs and don't do GUI) in HLA [ http://www.artofasm.com ] using its standard library and the program will execute (without any change to …
A couple more links on this subject:
http://webster.cs.ucr.edu/Articles/GreatDebate/index.html
http://members.save-net.com/jko@save-net.com/asm/opinion.htm
Hate to be pedantic, but actually, it *is* portable! As long as you stay on the same Arch anyway.
I just run across this today:
http://discuss.joelonsoftware.com/default.asp?joel.3.7054.16
which basically asks the same question. Pondering this, I came up with this analogy:
All the die-hard Amatuer (Ham) Radio people will continue to preach about all the reasons to learn Morse Code even though it is easy today to get an advanced license without ever hearing a 'dot and dash' sequence. There are only 26 letters in the alphabet, and if you learn one per day then you will have it mastered within a month... so why not do it? Voice transmissions take up a large bandwidth. When your entire neighborhood is talking and you can't find a clear channel to use, what are you going to do? If you know Morse, you can squeeze yourself into the airwaves.
Here is an example of someone putting their knowledge of assembly language to good use. http://invisiblethings.org/about.html Through all her talks, writings, and interviews, it is clear she *really* understands computers, operating systems, and the software that runs on them. It is also clear that she has developed a greate deal of competency in the understanding of assembly language. Yet, the programs she releases are not written in assembly. One does not have to produce assembly applications in order for that 'machine-learning' knowledge to be valuable.
{it says "Solved" but I will reply anyway}
The "masm32" package http://www.masm32.com/ is a collection of library files, examples, etc, plus "ml.exe" and related tools. The installer written for this package has trouble with network drives -- so make sure you are at the keyboard + monitor + box of the server which contains the HD you wish to install this package on. Some people question the legality of "ml.exe" (and other Microsoft tools) distributed with this package, so the PlatformSDK here link is provided. This is also a good source for various other tools and resources.
Version information:
http://www.masm32.com/mlcompat.htm
Other tools:
http://website.masm32.com/
Forum for questions:
http://www.masm32.com/board/index.php
The VERY LATEST VERSION of MASM from Microsoft is LEGALLY available via the GeneSys Project:
http://x86assembly.codegurus.org/
http://www.masm32.com/board/index.php?topic=5248.0
HI EVERY ONE
I want TASM code to show the real time in the screen in a sample way
thanks :-|
You can probably find a few examples in the Fidonet archives:
http://www.cet.com/~jvahn/80xfiles.html
This exercise gets you familiar with Ubuntu command-line tools for creating, navigating, and removing directories.
Follow these steps