在 x86 中读取多个输入
Read more than one input in x86
我需要读取输入并存储它,但输入需要超过 1 个数字,例如 45 或 55。
我已经让它工作了,但我认为可以让它变得更好。我是这样做的:
mov ah, 1
int 21h
mov ah, 0
mov cl, 0Ah
sub al, 30h ;
mul cl
mov bx, ax
mov ah, 1
int 21h
sub al, 30h ; '0'
add bx, ax
mov temp_val, bl
retn
可能吗?我无法通过其他方式做到这一点。
你的代码有一些问题
mov ah, 1
int 21h
mov ah, 0 ; <-- Here MOV AH,0 is useless because ...
mov cl, 0Ah
sub al, 30h
mul cl ; <-- ... MUL changes AH anyway
mov bx, ax
mov ah, 1
int 21h
sub al, 30h
; <-- Here you forgot MOV AH,0 so you can ...
add bx, ax ; <-- ... correctly add AX to BX
但如果您只需要输入 2 个字符,请考虑以下内容
mov ah, 1
int 21h
mov cl, 0Ah
sub al, 30h
mul cl
mov bl, al
mov ah, 1
int 21h
sub al, 30h
add bl, al ; Largest number is 99 so it fits in BL
甚至不使用 MUL 指令和更短的
mov ah, 1
int 21h
mov bl, al
mov ah, 1
int 21h
mov ah,bl
sub ax, 3030h
aad
mov bl, al ; Largest number is 99 so it fits in BL
我需要读取输入并存储它,但输入需要超过 1 个数字,例如 45 或 55。
我已经让它工作了,但我认为可以让它变得更好。我是这样做的:
mov ah, 1
int 21h
mov ah, 0
mov cl, 0Ah
sub al, 30h ;
mul cl
mov bx, ax
mov ah, 1
int 21h
sub al, 30h ; '0'
add bx, ax
mov temp_val, bl
retn
可能吗?我无法通过其他方式做到这一点。
你的代码有一些问题
mov ah, 1
int 21h
mov ah, 0 ; <-- Here MOV AH,0 is useless because ...
mov cl, 0Ah
sub al, 30h
mul cl ; <-- ... MUL changes AH anyway
mov bx, ax
mov ah, 1
int 21h
sub al, 30h
; <-- Here you forgot MOV AH,0 so you can ...
add bx, ax ; <-- ... correctly add AX to BX
但如果您只需要输入 2 个字符,请考虑以下内容
mov ah, 1
int 21h
mov cl, 0Ah
sub al, 30h
mul cl
mov bl, al
mov ah, 1
int 21h
sub al, 30h
add bl, al ; Largest number is 99 so it fits in BL
甚至不使用 MUL 指令和更短的
mov ah, 1
int 21h
mov bl, al
mov ah, 1
int 21h
mov ah,bl
sub ax, 3030h
aad
mov bl, al ; Largest number is 99 so it fits in BL