Thread: Converting Assembler Operators to Binary

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Converting Assembler Operators to Binary

    I'm making an assembler that runs off of CGI and hence, the processing will all be done in 100% C. I have a list of the equivalents of the Instructions in Assembler, and a guide on how to translate the operands in into binary (they have to be imbedded in the instruction). Operators how ever, are a different story. Anyone? There's no list in my book.

  2. #2
    *
    Guest
    There are only operands and operators. Operands are also called mnemonics (pronouned new-MON-ix).

    Binary is not a thing. It is a numbering system, like hex or decimal. It is not a what, but a HOW you look at RAM.

    If I look at a location in RAM in decimal I might see 0. If I look at it in hex, it might see 0x00, and if I look at it in binary I might see 00000000.

    All the same thing no matter how you look at it.

    Thus, to create assembly, you simply, using specific rules about your processor, create a 32-bit number whose bits reflect those that tell the processor what mnemonic it is, and then what its operands are. You might have to create a couple of other 8, 16, or 32-bit numbers to go with it, depending on the processor syntax for the given mnemonic.

    If you want to see what bit pattern an assembly instruction (again, a mnemonic, or operand) requires, you should get a processor book from the maker of that chip (eg. Motorola or Intel), or get a book at the bookstore about that chip.. eg. 8088, or 80386, etc.)

    So to recount: Let's _suppose_ you had an LDA mnemonic for "Loading a value into an Address location". It might be assembler like this:

    Code:
    ...
       NOP
       LDA  #5,bx                       ;put a 5 into register bx
       LDA  #10,ax                     ;put a 10 into register ax
       MUL bx,ax                        ;multiply the 2, putting result into bx
    ...
    In binary, you have to know how the processor knows what a register is (and hence what index applies to what register). You have to know how many bits are used to tell the CPU which mnemonic it's looking at.

    For example, Let's say all mnemonics require 6 bits to tell the CPU what the mnemonic is. You need 3 bits each for each registor (your imaginary processor only supports 7 registers), you need a sign bit, and a value for the operators.

    LDA #5,bx might look like this:

    11101000000000000000000101010011

    Which, in decimal is: 3892314451, or
    in hex is: 0x00E8000153.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I know what binary is. I know how to convert. I've done the exact same thing with the assembly insructions, but I have no list for the operators. That's all I'm looking for.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Assembly operators??

    There aren't any. Granted you can use the +, -, *, and / in assembly programs but that is usually because the assembler allows you to.

    Perhaps you are not using the right term.

    There are instructions and operands or opcodes and operands, R/M byte, and several other terms are used to describe an assembly statement. Look them up in an Intel manual.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    ...:sigh:

    Boy are you deaf as a horse? If you had been listening to *guest's reply you would have realized that therein lies the answer to your question. Do you want to find the pattern? Just look at it

  6. #6
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I'm not sure what exactly you want but if the intel manuals don't have it...

    http://www.intel.com/design/Pentium4/manuals/index.htm

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >I'm not sure what exactly you want but if the intel manuals
    >don't have it...

    If it is an Intel which Sean is talking about. Another interesting link on microprocessors:

    http://casl.csa.iisc.ernet.in/Comput...cture/Manuals/

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well my book calls them Operators. examples: The aforementioned arithmetic operators, HIGH, INDEX, LENGTH, LOW,OFFSET, MASK, PTR, SEG, SHL, SHR, SHORT, SIZE, THIS, TYPE, WIDTH. i'm also looking for the directives. Examples: ALIGN ENDP EVEN LABEL PROC IF ELSE .ERR .ERR1 ALIGN EQU EVEN LABEL ORG. DB DW DD DF DQ DT .CREF .LIST PAGE SUBTTL TITLE .XCREF .XLIST .LALL .LFCOND .SALL SFCOND TFCOND .XALL, and there are a lots of others which I can't be bothered typing in.
    Last edited by sean; 06-05-2002 at 01:27 PM.

  9. #9
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Seems you're using an Intel isn't it? I suggest you download the Intel manuals. There's lots of info in it. Or else take a look at this site:

    http://www.imada.ou.dk/~jews/PInfo/intel.html

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    No. The book is for IBM PCs It was written when DOS was state of the art. It's just your average Microsoft system

  11. #11
    *
    Guest
    In assembly language jargon, they are called operators or opcodes. The associated arguments are called operands.

    An operator is also called a 'mnemonic' because it is an abbreviated instruction. For example 'LDA' stands for "LoaD effective Address'. Likewise, 'NOP' stands for 'No OPcode'.

    First the last time, you need to get a book that is for the specific processor or family of processors you want to work with. Usually from the chip maker. This is an engineering book, not something you get at Amazon.com It will not only have all the engineering technical information, waitstates, cycle timing, buslining, etc., but it will also have every possible assembly instruction and what its associated bit pattern is, based on what operands are associated with it.

    For example, for the Pentium IV, here is the link to Intel's site that you want to get a hardcopy of the instruction set (opcode) reference manual.

    http://developer.intel.com/design/pe...als/245471.htm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. Converting From Binary Tree to Threaded Binary Trees
    By elton_fan in forum C Programming
    Replies: 15
    Last Post: 11-08-2007, 11:41 PM
  3. Replies: 3
    Last Post: 11-25-2006, 04:14 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM