NASM Forum > Using NASM

Convert MASM code to NASM

<< < (2/3) > >>

Frank Kotler:
Hi Azrael998,

Welcome to the forum.

Hi Debs,

This error message sounds like Linux to me. Your Masm code won't run in Linux. In fact, it won't tun on anything but a very old machine or in an emulator = Dosbox or such. This mat ve what you're supposed to be doing. Find out!

We can rewrite this code so it will run in Linux... or you can install Dosbox or some other emulator. Which are you  supposed to be doing?

Good job with the code so far. One problem: "lea" wants "[contents}" of memory. So:

--- Code: ---lea dx, [illegal]

--- End code ---
etc.
The other instructions are mostly the same as Masm.

Hang in there!

Best,
Frank


Azrael998:
Hi Frank Kotler, thank you very much for responding. My assignment is to convert the code so that it runs on linux, how can I do that?.

debs3759:
I don't know the Linux system calls, so won't be able to help with that, but I will reply with some pseudo code later to show how I would code it. I'll leave it to our Linux users to help converting system calls to Linux syscalls.

Does the 8 you are loading into CX mean you are only working with integer strings of 7 digits plus return, or 8 digits without? Do you need to test for overflows (numbers which are too long)? I can see you want to detect invalid key presses.

Azrael998:
The 8 being loaded in the CX register means 8 digits without return, yes I need to test for overflow.

debs3759:
Here is some basic pseudo code. I can expand on some of it using code that works on DOS or uses BIOS interrupts, but that would still need changing to use Linus system calls.

section .data
        msg1 db 'Enter the first binary number: ', 0DH, 0AH
        msg2 db 'Enter the second binary number: ', 0DH, 0AH
        msg3 db 'The sum of the given binary numbers: ', 0DH, 0AH
        illegal   db  'Illegal character. Try again.', 0DH,0AH
        str1  times 10 db 0
        str2  times 10 db 0
        result  times 11 db 0



section .text

        org     256           ; only needed if you code for a DOS environment and create a .com file

        read input strings from stdin (normally keyboard)(I would create a callable routine
                                                which takes the output address as its input)
        convert ascii string to binary digits, checking each character as you go.
                                                Store in bh and bl if the systems calls preserve them
        if any input character is invalid, output error msg
        if no errirs, add the resulting numbers
        convert back to am ascii string
        display the output



I made the strings longer than you need so that you can test for input that is too long, as well as having room for the carriage returm (to help check the length of the input). DOS has an interrupt that takes the length of input as an argument, so I assume Linux has that as well,

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version