Encoding Assembly language Instruction

Posted on 2009-02-18
Last Modified: 2012-05-06
Bytes are arranged in order of increasing memory address and the H.O. byte of a constant always appears in the highest memory address..what does it mean?
Question by:msivask1
    LVL 53

    Accepted Solution

    Obviously, I don't know the context, but the phrase means that the bytes of some object that is placed in memory will be arranged at increasing memory addresses. So, the first byte will be at address x, the second byte at address x+1, etc.

    Furthermore, the high-order (H.O.) byte of a constant will always be at the highest memory address. So, for example, if a constant is 4 bytes long, and if it's stored at address x, then the high-order byte of the constant will be at address x+3, and the low-order byte at address x.

    The high-order byte of a constant (integer) value is the byte that contains the highest order bits of the value. The highest order bits are the bits for the highest powers of 2. For example the binary value 100 (4 in decimal) has 1 as the high-order bit (the left-most bit).

    Author Comment

    encoding y86 instructions
    add( [2ff+bx], cx )
    as per format, 8 bits are designated the following values
    i       i     i         r       r      m    m     m
    1    0     1       1       0     1      0      1

    i i i   --   for add,sub...
    r  r   --- destination bits 1 0 for cx
    m m m --  source bits indexed address mode [xxxx+bx] is 101

    so this is b5

    since the instruction involves memory reference, extra 16 bits are also used to encode above ins.

    the constant represented in the above indexing address mode is 2ff

    that 2ff is represented using 16 bits that is 2 bytes by
    ff,02 boubt comes here.

    1. why it is represented in reverse direction?
    2. if it is in backward direction why is there a 0 in between?.it should not be just ff2?

    as a whole the given ins is encoded as b5,ff,02..


    Author Closing Comment

    I understand the concept...
    But i dont understand the reason for this arrangement
    " Higher order byte of a constant will always be at the highest memory address"

    Thank you so much...

    Author Comment

    Got the point..neednot consider my recent question of why there is a 0 inbetween..
    thank u ..just did not get the reason for this arrangement of bytes..
    LVL 53

    Expert Comment

    >> just did not get the reason for this arrangement of bytes..

    It's just a convention. A choice made in the design, for reasons of performance. If the low-order bits are in the lower addresses, that means they can be accessed more directly (most values will be small values anyway). It is also convenient for casting between integer types. For example, when casting from a 4 byte integer type to a 2 byte integer type, all that needs to be done is use the two low-order bytes, and they are right there, at the start address of the 4byte integer.

    Author Comment

    sorry...i was not able to understand your point..

    LVL 53

    Expert Comment

    Reading up on endianness should make things clearer. Here's a good start :


    Author Comment

    thank u...let me go through..

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    ASM problem 2 31 341
    Bomb lab phase_5 1 1,332
    Add placeholder(*) block functionality to Windows 7 hosts 1 871
    What are the %fs and %gs registers? 3 1,196
    Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now