'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? Program must run on 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
Solution 1:[1]
A first step might be to convert the code to NASM source code for DOS. To do this you'd mostly delete the unnecessary stuff (e.g. getchar PROC becomes getchar:, getchar ENDP gets deleted, etc). You'd also have to figure out how to get NASM to generate a DOS compatible ".exe" file (see 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.
However; Windows uses very different APIs with more baggage. 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. For some of it; the nature of the API is also fundamentally different. 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. Of course (modern) Windows requires 32-bit or 64-bit code too (which also means very different calling conventions).
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).
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brendan |
