如何将8086 emu汇编程序转换为可兼容的linux汇编 [英] How to convert an 8086 emu assembly program to linux assembly comaptible
问题描述
我正在编写将十六进制(A-F)转换为十进制的代码.我设法在8086 emu上编写了它,但在Linux上却需要它.我需要帮助.
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.
该代码在8086仿真器n个窗口上绝对可以正常工作.但是我无法将其转换为Linux语法.我对组装的Linux语法不熟悉.
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.
这是我的8686代码.
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
推荐答案
要进行这种转换,您必须考虑两件事:
To do such a conversion, you have to consider two things:
-
您的代码是分段的16位汇编代码.Linux不使用分段的16位代码,而是使用固定的32位或64位代码.
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.
平面"表示选择器( cs
, ds
, es
, ss
段"寄存器,但选择器"(在32位模式下)具有预定义的值,请勿更改.
"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.
在32位模式下,CPU指令(以及汇编程序指令)与16位模式有些不同.
In 32-bit mode the CPU instructions (and therefore the assembler instructions) are a bit different from 16-bit mode.
中断与环境有关.例如, int 21h
是一个MS-DOS中断,这意味着 int 21h
仅在所使用的操作系统与MS-DOS兼容或您使用某些软件(例如模拟MS-DOS的"8086 emu".
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在32位程序中使用 int 80h
来调用操作系统功能.不幸的是, int 21h
的许多非常方便"的功能在Linux中不存在.一个示例是键盘输入:
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:
如果您不希望使用默认行为(用echo读取完整的行;键入完整的行时程序可以读取行的第一个字符),则必须发送所谓的 ioctl()
-编码到系统...
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...
当然,Linux系统调用的语法与MS-DOS的语法不同: int 80h
的函数 EAX = 9
(链接磁盘上的文件)是与 int 21h
的 AH = 9
完全不同的功能(在屏幕上打印字符串).
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).
您已使用标签 att
标记了您的问题.但是,还有用于Linux的汇编器,可以汇编 intel
样式的汇编代码.
You have tagged your question with the tag att
. There are however also assemblers for Linux that can assemble intel
-style assembly code.
这篇关于如何将8086 emu汇编程序转换为可兼容的linux汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!