Skip to content

x86 ASM: translate from MASM to NASM dialect - #241

Open
darealshinji wants to merge 2 commits into
ip7z:mainfrom
darealshinji:nasm-2
Open

x86 ASM: translate from MASM to NASM dialect#241
darealshinji wants to merge 2 commits into
ip7z:mainfrom
darealshinji:nasm-2

Conversation

@darealshinji

Copy link
Copy Markdown

NASM is a widespread portable open source assembler. Unlike ASMC (currently required to build on Linux) it's written entirely in C and available for installation by pretty much any package manager. This may also make it easier to port or use the asm code on other platforms (macOS, BSD). On Windows it can also be installed with winget.

I've tested it a bit on 64 bit Linux and didn't experience any issue.

I've used this shell script to compare the disassembled object files generated by nasm and asmc:

if [ "x$1" = "x" ]; then
    exit 1
fi

if [ "$1" = "LzFindOpt" ] || [ "$1" = "LzmaDecOpt" ]; then
    list="elf64 win64"
else
    list="elf32 elf64 win32 win64"
fi


PATTERN='s|^\?_[0-9][0-9][0-9]:|      |g; s|;.*||g; / j[a-z] /d; / j[a-z][a-z] /d; /:/d'


for FMT in $list ; do
    if [ $FMT = elf64 ] ; then
        ASMC="asmc64 -elf64 -Dx64 -DABI_LINUX"
    elif [ $FMT = win64 ]; then
        ASMC="asmc64 -win64 -Dx64"
    elif [ $FMT = elf32 ]; then
        ASMC="asmc -elf -DABI_LINUX"
    else
        ASMC="asmc -coff"
    fi

    $ASMC -c -Fomasm.o x86-masm/$1.asm
    nasm -Ix86 -f$FMT -o nasm.o x86/$1.asm
    objconv -fnasm masm.o
    objconv -fnasm nasm.o
    sed -i -e "$PATTERN" masm.asm
    sed -i -e "$PATTERN" nasm.asm
    set +e
    diff -u masm.asm nasm.asm > ${1}_$FMT.diff
    #mv masm.asm masm_$FMT.asm
    #mv nasm.asm nasm_$FMT.asm
    rm -f masm.* nasm.*
    set -e
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant