0

I tried to compile the following codes using an online compiler.

enter image description here

This is the code:

section .data
    EAX:12131415h
    EDX:12345678h
    
section .code
_start:
    Rol EAX, 16
    Rol EAH, 8
    Rol EAL, 8
    Rol EDX, 16
    Rol EDH,  8
    Rol EDL, 8
Int 21h
.end

This is the error that I got: enter image description here

Does anyone know how to fix this error?

This is the problem that I tried to answer:

We have an 8 bytes width number, so we save the lower bytes in EAX and higher bytes in EDX: for example number 1234567812131415h will be saved like EAX = 12131415h, EDX = 12345678h. Write a general-purpose program that is able to reverses any number 8 bytes width number that its least significant bytes are in EAX and its most significant bytes are saved in EDX . Note: Reverse means that our sample number becomes: EAX=78563412h and EDX = 15141312h.

hongkongbboy
  • 300
  • 1
  • 5
  • 14
  • There are no such registers as `EAH, EAL, EDH, EDL`. See https://en.wikibooks.org/wiki/X86_Assembly/X86_Architecture#General-Purpose_Registers_(GPR)_-_16-bit_naming_conventions, especially the table "identifiers to access registers and parts thereof". – Nate Eldredge Feb 16 '21 at 04:21
  • What exactly are you trying to accomplish with this code? It doesn't seem to make much sense. – Nate Eldredge Feb 16 '21 at 04:22
  • 1
    Oh, and it looks like the `mycompiler.io` x86-64 asm mode runs its programs on 64-bit Linux. Your `Int 21h` is a 16-bit MS-DOS API and won't work at all. – Nate Eldredge Feb 16 '21 at 04:24
  • I updated the question with the problem that I tried to solve. – hongkongbboy Feb 16 '21 at 04:28
  • I tested the code by changing line 2 and 3 with `EAX$:12131415h` and `EDX$:12345678h`. I got the following errors for both: `error: parser: instruction expected` – hongkongbboy Feb 16 '21 at 04:31
  • This is the online compiler that I used https://www.mycompiler.io/new/asm-x86_64 – hongkongbboy Feb 16 '21 at 04:32
  • 1
    EAX is a legal label name in NASM, but you can only declare it with `$EAX:`. You can load from it with `mov eax, [$EAX]` to disambiguate from the reg name. Unlike `loop:`, the `:` doesn't force treating as a label instead of a reg name. (You can use `nm` to verify that actual symbol name is EAX, not `$EAX`, so you could interoperate with a C `int EAX;` global var.) The other problem is `label: number` without a DD directive; possibly the OP thought that would initialize registers. (To set up for their emulation of bswap eax and bswap edx using the wrong register names for AH and so on.) – Peter Cordes Feb 16 '21 at 04:33
  • @hongkongbboy: yes, did you miss the rest of my comment (which I reposted to clean up other parts, not the part about needing `dd`)? `label: number` isn't valid, you need `label: dd number`. `dd` is the "instruction" in that line which is missing. – Peter Cordes Feb 16 '21 at 04:35
  • @PeterCordes Sorry, I haven't learned how to use `dd` and apply `$` symbol yet. – hongkongbboy Feb 16 '21 at 04:42
  • 1
    You don't really want to mess around with `$EAX` symbol names, just use label names that aren't the same as registers. As for using `dd`, you need to understand that if you want to put static data in memory. See [How do labels and dd declarations work in NASM? What's the C equivalent?](https://stackoverflow.com/q/40453482), the first duplicate. (Of course, `mov eax, 0x12345678` at the start of your code would avoid having to load from memory.) – Peter Cordes Feb 16 '21 at 04:54

0 Answers0