jerluc
jerluc

Reputation: 4316

80x86 Assembly - Very basic I/O program conversion to Linux from Windows

So my first day of Assembly class, and what do you know? My professor teaches everything on her Windows box, using Windows API calls, etc. which is fine except that I'm running Ubuntu on my box..

Basically, I'm hoping I can find either a workaround or some form of common-grounds in order for me to get my assignments done.

Today, our first programming assignment was to input two integers and output the sum. I followed my professor's code as follows:


.386
.model      flat

ExitProcess PROTO NEAR32 stdcall, dwExiteCode:DWORD

include     io.h

cr      EQU 0dh
lf      EQU 0ah

.stack      4096

.data

szPrompt1   BYTE    "Enter first number: ", 0
szPrompt2   BYTE    "Enter second number: ", 0
zLabel1     BYTE    cr, lf, "The sum is "
dwNumber1   DWORD   ?               ; numbers to be added
dwNumber2   DWORD   ?
szString    BYTE    40 DUP (?)          ; input string for numbers
szSum       BYTE    12 DUP (0)          ; sum in string form
szNewline   BYTE    cr,lf,0



.code                           ; start of main program code
_start:
    output      szPrompt1               ; prompt for ?rst number
    input       szString,40                 ; read ASCII characters
    atod        szString                ; convert to integer
    mov         dwNumber1,eax               ; store in memory
    output      szPrompt2               ; repeat for second number
    input       szString,40
    atod        szString
    mov         dwNumber2,eax
    mov         eax,dwNumber1               ; first number to EAX
    add         eax,dwNumber2               ; add second number
    dtoa        szSum,eax               ; convert to ASCII characters

    output      szLabel1                ; output label and results
    output      szSum
    output      szNewline

    INVOKE      ExitProcess,0               ; exit with return code 0

    PUBLIC      _start                  ; make entry point public
    END                             ; end of source code

Simple and straightforward enough, yeah? So I turned it in today all linked up from the crappy school computers. And I completely understand all the concepts involved, however, I see 2 main issues here for if I actually want to assemble it on my box:

1)

.model        flat
2)
ExitProcess PROTO NEAR32 stdcall, dwExiteCode:DWORD
And Both of which I've heard are very Windows-specific. So my question is how can I mutate this code to be able to assemble on Linux?

Sorry If I'm missing any details, but I'll let you know if you need.

Thanks!

Upvotes: 3

Views: 828

Answers (1)

bdonlan
bdonlan

Reputation: 231143

Assembly code is, generally speaking, almost always platform specific. Indeed, the very syntax varies between assemblers, even within the same hardware and OS platform!

You'll also probably have problems with that io.h there - I would bet it's making a lot of calls into win32 APIs.

I would recommend simply using wine, along with a copy of whatever assembler your professor is using, to run your professor's examples. If it can run things like Microsoft Office and Steam, it can certainly run some trivial example code :)

Upvotes: 3

Related Questions