[英]How can i rewrite assembly code using Dos to NASM assembly
how can i convert this assembly code using Dosbox to classic i8086 NASM code which can be compiled on Win?我如何使用 Dosbox 将此汇编代码转换为可以在 Win 上编译的经典 i8086 NASM 代码? Program must run on Intel 8086.程序必须在 Intel 8086 上运行。
.model SMALL
.stack 50
.data
RET1 DB 10,13,'Bolo zadane iba jedno slovo$'
POCET Dw 0
poc db 0
zhod dw 0
sum db 0
suma dw 0
jed db 0
des db 0
sto db 0
.code
getchar PROC
MOV AH,01
INT 21H
RET
getchar ENDP
napln proc
mov ax,50
mov si,ax
mov ax,150
mov di,ax
mov cx,pocet
pokr: mov bl,[si]
mov [di],bl
inc di
inc si
dec cx
cmp cx,0
jnz pokr
ret
napln endp
START: mov ax,50
mov si,ax
MOV AX,@data
MOV DS,AX
slovo: CALL getchar
CMP AL,32
JZ MEDZ
CMP AL,13
JZ malo
cmp poc,0
mov cx,pocet
jnz kontr
skok: mov [si],al
inc si
INC POCET
inc poc
JMP slovo
kontr: mov si,50
kon: cmp al,[si]
jz slovo
inc si
dec cx
cmp cx,0
jnz kon
jmp skok
MEDZ: cmp poc,0
jz slovo
call napln
CALL GETCHAR
CMP AL,13
JZ MALO
CMP AL,32
JNZ CITAT
JMP MEDZ
malo: MOV DX,offset RET1
MOV AH,09
INT 21H
mov ax, 4c00h
INT 21h
CITAT: CMP AL,13
JZ posledne
cmp al,32
jz space
mov si,150
mov cx,pocet
zisti: cmp al,[si]
jnz dalej
mov bl,0
mov [si],bl
inc zhod
dalej: inc si
dec cx
cmp cx,0
jnz zisti
dalsi: CALL GETCHAR
JMP CITAT
posledne: mov cx,pocet
cmp zhod,cx
jnz prevod
inc sum
inc suma
jmp prevod
space: mov cx,pocet
cmp zhod,cx
jnz zle
inc sum
inc suma
zle: mov zhod,0
call napln
jmp dalsi
prevod: jmp vypis
vypis:
MOV AH,02
MOV DL,0AH
INT 21H
MOV AL,sum
ADD AL,48
MOV DL,AL
INT 21H
mov ax, 4c00h
INT 21h
END START
Or can someone do it?或者有人可以做到吗? The program should list the number of words containing all the letters of the first word from the input string.该程序应列出包含输入字符串中第一个单词的所有字母的单词数。 The statement should be in the decimal system.该语句应采用十进制。 This is my first experience with assembly language so i dont know how can i do it这是我第一次使用汇编语言,所以我不知道该怎么做
A first step might be to convert the code to NASM source code for DOS.第一步可能是将代码转换为适用于 DOS 的 NASM 源代码。 To do this you'd mostly delete the unnecessary stuff (eg getchar PROC
becomes getchar:
, getchar ENDP
gets deleted, etc).为此,您将主要删除不必要的内容(例如getchar PROC
变为getchar:
, getchar ENDP
被删除,等等)。 You'd also have to figure out how to get NASM to generate a DOS compatible ".exe" file (seehttps://www.nasm.us/xdoc/2.15.05/html/nasmdoc9.html#section-9.1 ).您还必须弄清楚如何让 NASM 生成与 DOS 兼容的“.exe”文件(请参阅https://www.nasm.us/xdoc/2.15.05/html/nasmdoc9.html#section-9.1 ) . After doing that (and testing that it works properly);这样做之后(并测试它是否正常工作); a second step might be to convert the NASM source code for DOS into NASM source code for Windows.第二步可能是将 DOS 的 NASM 源代码转换为 Windows 的 NASM 源代码。
However;然而; Windows uses very different APIs with more baggage. Windows 使用非常不同的 API,但行李更多。 Specifically, you're supposed to use DLLs (and dynamic linking) so that Microsoft can radically change the kernel's API without breaking everything, and the kernel's APIs are deliberately undocumented to try to prevent people from writing code that will break when the kernel is changed.具体来说,您应该使用 DLL(和动态链接),以便 Microsoft 可以在不破坏所有内容的情况下从根本上更改内核的 API,并且故意不记录内核的 API 以试图防止人们编写在更改 kernel 时会中断的代码. For some of it;对于其中的一些; the nature of the API is also fundamentally different. API 的性质也根本不同。 For example, rather than calling the API to get the user's next key press, you register an event handler and the API calls you when the user presses a key.例如,不是调用 API 来获取用户的下一次按键,而是注册一个事件处理程序,当用户按下某个键时 API 会调用您。 Of course (modern) Windows requires 32-bit or 64-bit code too (which also means very different calling conventions).当然(现代)Windows 也需要 32 位或 64 位代码(这也意味着非常不同的调用约定)。
The result is that it's probably easier to design and write a new program for Windows (instead of converting an old program for DOS).结果是为 Windows 设计和编写新程序可能更容易(而不是为 DOS 转换旧程序)。
With this in mind;考虑到这一点; a better first step would be to convert the original program's source code into a document that describes its behavior (in plain English with no executable code).更好的第一步是将原始程序的源代码转换为描述其行为的文档(使用简单的英语,没有可执行代码)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.