【发布时间】:2018-06-18 17:08:14
【问题描述】:
8086 编写一个程序,从输入中获取一个字符串并在每两个字母之间插入一个空格
使用 nasm 和 MSDOS
我做了以下代码,但它不工作
start:
mov ax,data
mov ds, ax
mov es, ax
mov cx, size;cx will contain size,we need it to
; check if we have got 10 inputs from key board
lea dx, Enter_string;it will display a text on screen to enter text
mov ah, 9
int 21h
call get_string;input string from keyboard
mov ax, 4ch;terminating
int 21h
get_string:
mov si, 0; si will be used as index
mov bx, offset string
get_char:
mov ah, 1; get a char from keyboard
int 21h
mov [bx][si], al; saving input in string
inc si
cmp si,cx;if si=7 than, no need to take more input
jne get_char
ret
【问题讨论】:
-
不工作怎么办?看起来它甚至不会在没有定义
Enter_string符号的情况下进行组装。 (或者在 NASM 语法中,即使有定义也没有。使用mov dx, Enter_string,因为lea dx, [Enter_string]更慢/更大,并且仍然是16 位绝对寻址。)无论如何,这不是minimal reproducible example。此外,如果这是一个 DOS.com程序,则需要org 0x100,而mov ax, data看起来不正确。我认为您需要一些其他语法来获取细分基础。 -
一个明显的问题,甚至来自古老的记忆:
mov ax, 4ch。4c需要放在 AH 中,而你要在 AL 中返回的值——但就目前而言,这是将4c放在 AL 中,00放在 AH 中。我不记得 DOS 定义了一个函数 0,所以我不确定它现在会做什么(但几乎可以肯定不会终止)。