在字符串程序集 8086 masm 末尾提取数字
Extracting digit at end of string assembly 8086 masm
我必须提取存储在 si 寄存器中的数字。这是我的代码
lea si, userInput
inc si
mov bx, [si]
mov dx, [si+bx]
add dx, 30h
mov ah, 2h
int 21h
所以我认为如果我像 mov dx, [si+2]
这样在 dx 寄存器中放入硬值,代码工作正常,但是如果尝试使用 mov dx, [si+bx]
它不起作用并且不会按预期提供输出
假设您的 userInput 指向 DOS 的缓冲输入函数 0Ah 所需的输入结构,这些是我更正您的代码的建议:
- 第二个字节保存输入的字符数。您错误地将其检索为 word.
- 输入由 1 个字节 宽的字符组成。您目前检索它时,就好像它们是 2 个字节。
- 由于输入已经由个字符组成,您不需要对其进行任何转换。 (尝试
mov dx, 30h
)此字符可以表示(数字)数字、字母、标点符号或其他任何内容,这一事实不会改变这一点。
您的代码将变为:
lea si, userInput
inc si
mov bl, [si] ;Number of inputted characters
mov bh, 0 ;Need to zero to be able to use the whole address-register BX next
mov dl, [si+bx] ;Retrieve the last inputted character (right before the terminating CR)
mov ah, 02h
int 21h ;Display the character
我必须提取存储在 si 寄存器中的数字。这是我的代码
lea si, userInput
inc si
mov bx, [si]
mov dx, [si+bx]
add dx, 30h
mov ah, 2h
int 21h
所以我认为如果我像 mov dx, [si+2]
这样在 dx 寄存器中放入硬值,代码工作正常,但是如果尝试使用 mov dx, [si+bx]
它不起作用并且不会按预期提供输出
假设您的 userInput 指向 DOS 的缓冲输入函数 0Ah 所需的输入结构,这些是我更正您的代码的建议:
- 第二个字节保存输入的字符数。您错误地将其检索为 word.
- 输入由 1 个字节 宽的字符组成。您目前检索它时,就好像它们是 2 个字节。
- 由于输入已经由个字符组成,您不需要对其进行任何转换。 (尝试
mov dx, 30h
)此字符可以表示(数字)数字、字母、标点符号或其他任何内容,这一事实不会改变这一点。
您的代码将变为:
lea si, userInput
inc si
mov bl, [si] ;Number of inputted characters
mov bh, 0 ;Need to zero to be able to use the whole address-register BX next
mov dl, [si+bx] ;Retrieve the last inputted character (right before the terminating CR)
mov ah, 02h
int 21h ;Display the character