How to convert an 8086 emu assembly program to linux assembly comaptible

点点圈 提交于 2021-01-29 14:17:12

问题


I am writing a code to convert hex (A-F) to decimal in assembly. I managed to write it on 8086 emu but I need it for linux. I need help.

The code works absolutely fine on 8086 emulator n windows. But I am unable to convert it into Linux syntax. I am not familiar with the Linux Syntax for assembly.

This is my 8686 code.

org 100h
.model small
.stack 100h
.data
msg1 db 'Enter a hex digit:$'
msg2 db 'In decimal it is:$'
.code
main proc
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,9
int 21h

mov ah,1
int 21h
mov bl,al
sub bl,17d ; convert to corrosponding hex value
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
lea dx,msg2
mov ah,9
int 21h
mov dl,49d ;print 1 at first
mov ah,2
int 21h
mov dl,bl
mov ah,2 ; print next value of hex after 1
int 21h
main endp
end main
ret

回答1:


To do such a conversion, you have to consider two things:

  1. Your code is segmented 16-bit assembly code. Linux does not use segmented 16-bit code, but either flat 32-bit or 64-bit code.

    "Flat" means that the selectors (cs, ds, es, ss which are not "segment" registers but "selectors" in 32-bit mode) have a pre-defined value which should not be changed.

    In 32-bit mode the CPU instructions (and therefore the assembler instructions) are a bit different from 16-bit mode.

  2. Interrupts are environment dependent. int 21h for example is an MS-DOS interrupt, which means that int 21h is only available if the operating system used is compatible to MS-DOS or you use some software (such as "8086 emu") that emulates MS-DOS.

    x86 Linux uses int 80h in 32-bit programs to call operating system functions. Unfortunately, many quite "handy" functions of int 21h are not present in Linux. One example would be keyboard input:

    If you don't want the default behavior (complete lines are read with echo; the program can read the first character of a line when a complete line has been typed), you'll have to send a so-called ioctl()-code to the system...

    And of course the syntax of Linux system calls is different to MS-DOS ones: Function EAX=9 of int 80h (link a file on the disk) is a completely different function than AH=9 of int 21h (print a string on the screen).

You have tagged your question with the tag att. There are however also assemblers for Linux that can assemble intel-style assembly code.



来源:https://stackoverflow.com/questions/55605062/how-to-convert-an-8086-emu-assembly-program-to-linux-assembly-comaptible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!