Search code examples
assemblybinaryfilesdata-conversion

How many Bytes does .fill .long mean in assembly?


i have a script from github https://github.com/akatrevorjay/edid-generator

which is written in assembly, now i want to do some more actions with this Edid Stuff and because i never did assembly im writing it in Python. For that i need to know how many bytes

  1. .ascii
  2. .fill 7,2,0x0101
  3. .long
  4. .data

normally have to "convert" it in python.

If it helps here is the full code line for each:

start1:         .ascii  "Linux #0"
                .fill   7,2,0x0101      /* Unused */
serial_number:  .long   SERIAL
                .data (Dont have more here)

Solution

  • These ones are simple

    • .long value puts a long value (4 bytes)
    • .word value puts a word value (2 bytes)
    • .byte value puts a byte value (1 byte)
    • .ascii "text" just puts the bytes of the text without NUL terminator

    Example

    .ascii "HELLO"

    is the same as

    .byte 'H'
    .byte 'E'
    .byte 'L'
    .byte 'L'
    .byte 'O'
    

    which is the same as

    .byte 'H', 'E', 'L', 'L', 'O'
    

    This one is less obvious:

    .fill repeat , size , value

    It will put repeat times the value value with the size size

    Examples

    .fill 3, 2, 0xab

    is th same as

    .word 0xab, 0xab, 0xab

    .fill 3, 1, 0xab

    is the same as

    .byte 0xab, 0xab, 0xab

    Complete example:

    .ascii "HELLO"
    .fill 3,2,0xab
    .word 5
    .long 6
    

    this will give you these bytes in memory on a little endian system:

    'H', 'E', 'L', 'L', 'O', 0, 0xab, 0, 0xab, 0, 0xab, 0, 5,   0, 0, 0, 6
    |   .ASCII              |  .FILL                   | .WORD |   .LONG  |