Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Questions about assembly for people that can program in it?

Ok to start this off im a programmer who knows many high level languages such as c# a little c++ XNA ect. Im trying to teach myself assembly. My teacher found a book and ive been reading it. I have a few questions for those who know the language. OK first question 1. Why do you hav to start programming at address 0100? They say to start from there but never explain why. Why cant you start at adress 0000 if there is one. second question 2. When doing a command suck as "mov dx,0200 does the letters dx stand for anything or r they just random variables people online use. Like can i make them any letters such as er or can they be longer than 2 letters like variable. third question 3. Im trying to do the basic hello world program to start of and get the flow of assembly but idk its like i cant get the rythm of assembly im getting better but its still kinda hard. How does the basic hello world program work i would like for some1 to copy some code to make the program in assembly and explain what each line does in a dumbed down way lol. What does jmp do? i know it jumps to a certain line but the guy in the video doesnt even seem to use that line he jumped to. Is jumping like calling a method in c++ or c#? ill post the links to the video at the end of this. Just give me tips on how to learn the language. Like i see the guy using "-a 0100" which he says tells it to start at a certain point and he also uses "-h 014b 0100" and "rex " and ''-n printchar.com" what does these wierd commands do it doesnt look like assembly ad if its not or is where do i learn them from and what r they called. What does "int 21" do? And how would you print out an entire string without having to declare each letter indivualy like in the second video ill post. Please explain theese codes to me and i apologize for bothering you with my problems.

video #1- http://www.youtube.com/watch?v=t24yLkrjVKU&feature...

video #2- http://www.youtube.com/watch?v=9Qn84QxX-zs&feature...

and o yay forgot to ask how does assembly variables work.

Its been my dream since ive become a programmer to learn this language so please help ill do anything to learn this wonderful language and thx. :)

1 Answer

Relevance
  • Ilie
    Lv 5
    10 years ago
    Favorite Answer

    Hi,

    Next time, please don't write anything in one paragraph, it's hardly readable. Also, know that assembly language is a family of languages, you need to tell us which on you are talking about; it's platform-specific (e.g., x86 assembly is different from ARM assembly). The ABI is sometimes also relevant---judging by your question, I take it you're talking about x86 assembly under DOS.

    1. It's 0x100 (i.e., hexadecimal) and you don't; that's specific to the .COM executable format. The reason behind this is that the .COM format has its traces in an older operating system called CP/M. CP/M loaded the code at offset 0x100h due to the fact that the first 256 (or 0x100) bytes were used for the zero page, a structure containing all sorts of information that the OS passed to the program. Due to backwards compatibility, MS-DOS also provides a similar structure called the PSP (Program Segment Prefix), which can be read and used by programs running in the DOS environment.

    2. Registers aren't really variables: you have a limited number of them and they are stored inside the CPU itself, not inside separate memory chips. DX is the name Intel gave to one of their 16-bit GPRs (General-Purpose Registers). Here's a list of all the x86 16-bit GPRs and what they stand for:

    AX = accumulator

    BX = base

    CX = count

    DX = data

    SI = source index

    DI = destination index

    BP = base pointer

    SP = stack pointer

    So what does the X in the first 4 registers stand for? It doesn't stand for anything; it means both the high-order byte and the low-order byte are used. Their high- and low-order bytes can be accessed independently, as 8-bit registers (e.g., AH, AL, BH, BL, etc.). The others can only be accessed as 16-bit registers. Note that 32-bit x86 CPUs add 32-bit registers (e.g., EAX, EBX, where the "E" stands for "extended"), and x86-64 CPUs add 64-bit registers (e.g., RAX, RBX, where the "R" stands for "REX," which you shouldn't worry about for the time being).

    3. I don't have enough room to do it here (there's a limit on how long an answer on Yahoo! Answers can be), and you have not mentioned what assembler you are using (they all have slightly different syntaxes, as assembly isn't a standardized language)---I suppose you're using MASM. You're in luck, one of the best x86 assembly language books is written for MASM and has also been made freely available for download by its author.

    Book: http://homepage.mac.com/randyhyde/webster.cs.ucr.e...

    Lab manual: http://homepage.mac.com/randyhyde/webster.cs.ucr.e...

    Companion library: http://webster.cs.ucr.edu/AsmTools/MASM/stdlib/std... (you will need this to test some of the examples in the book)

    This should answer everything. For now, know that assembly is nothing like C++, or C#. It's an entirely different programming paradigm and you need to use a different different mindset when programming in it; there are no variables, no types, no objects, no classes, no templates, no memory allocation or garbage collectors, etc. You only have the building blocks upon which those things are built. Other languages have yet other paradigms; if you try programming in Lisp, Prolog, or Smalltalk, you will see that they are nothing like what you are probably used to.

    INT 21h is how you make a system call in DOS; this is how you access the DOS API for things like file manipulation or printing strings. It can do different things based on the contents of your registers. System calls in DOS use a software interrupt mechanism (hence the "INT") and the handler used is 21h. You will get more familiar with this when the time is right.

    4. You don't have variables. What you do have, is access to memory. You put some data at a specific address and then you can read it or write to it later. Unlike other languages, such as C#, you can store a single byte and read it as part of a 4-byte value (i.e., including the bytes surrounding it), or you can store 4 bytes and only read 1 of them. Each byte is considered its own separate thing and you can interpret them however you like. The CPU doesn't know whether you're data is a string or an integer or even more code (since the latter is also stored as bytes), it depends on how your code treats it.

    I advise you that _after_ you read the book I linked you to, you start using the official x86 documentation.

    Intel CPUs: http://www.intel.com/content/www/us/en/processors/...

    AMD CPUs: http://developer.amd.com/documentation/guides/Page...

    Cheers,

    Bogdan

Still have questions? Get your answers by asking now.