4

I have assembly code in a text file and I don't know how to run it. I wish you can help me with detailed explanation. Thank you

rim luck
  • 95
  • 1
  • 1
  • 2
  • 2
    Which architecture, operating system, and assembler has that file been written for? – fuz Apr 15 '19 at 19:44
  • 3
    Unlike "high-level" operating languages, assembler code will only work on a certain CPU type: Assembler code written for x86 (typical PCs) won't work on an ARM CPU (Raspberry Pi). And x86 PCs even have different operating modes requiring specific code. Different operating systems require different code. And finally different programming tools ("assemblers") require a different syntax. If you don't post the code file so we can see it, there is absolutely no chance that we can help you. – Martin Rosenau Apr 16 '19 at 06:18

1 Answers1

5

Warning: never run code you don't know. In the case of assembly it can crash your system, or worse.

Assuming your assembly code is x86, And assuming it doesn't look like only rows of "01101010" or "de876f1a6bc37" And assuming that you are on Windows,

  1. Set up your development environment: https://ccm.net/faq/1559-compiling-an-assembly-program-with-nasm#compiling-an-assembly-program-with-nasm-for-windows
  2. Copy the assembly code
  3. Open notepad
  4. Paste the code
  5. Save on your desktop as "assembly.asm"
  6. Hold shift, right click on your desktop, select "Open command window here" from the dropdown
  7. Enter the following two commands:
  8. nasm -f win32 assembly.asm -o test.o
  9. ld test.o -o assembly.exe

Again, be careful with assembly. You also might not get output, so you won't know the output of your program.

AnnoyinC
  • 426
  • 4
  • 17
  • 1
    You're also assuming that it's NASM syntax for *32-bit* x86 for Windows. If it was written for Linux (e.g. with `int 0x80` system calls), it will assemble + link but crash on Windows. And there are many other assembler syntaxes for x86, including MASM being common on Windows. You're making a lot more assumptions than just "x86". – Peter Cordes Apr 17 '19 at 01:55
  • 1
    can you please answer this question assuming we're on linux and using x86 ? – Gray Hat Aug 24 '20 at 09:37
  • @GrayHat https://stackoverflow.com/questions/3314919/compile-run-assembler-in-linux mind the difference in syntax, if it's NASM or something else – AnnoyinC Aug 25 '20 at 11:23
  • 3
    Assembly itself will not crash your computer at all. This goes for any other language. – Epic Speedy Jan 15 '22 at 19:55