汇编输入一个数 再显示这个数?
我的意图是输入一个数后 ENTER 程序马上再显示这个数出来 貌似0-9可以用 SUM AL 30H来搞 2位 3位 多位的数怎么弄 是不是要存在一个字符数组里然后 通过单个字符转换
为数字 并循环输出?
有没有其他的方法?
程序代码:;//////////////////////////////////
stack segment para stack 'stack'
db 1024 dup(?)
stack ends
;////////////////////////////////////
data segment para stack 'stack'
input db 'Please input a number:$'
crlf db 0dh, 0ah, '$'
output db 'The result is :$'
;----------------------------
buffer_size db 50 ; max string length = 50
actual_size db ? ; actual string length
chars db 50 dup (20h) ; store from here
data ends
;/////////////////////////////////////////////
code segment
assume ds:data, cs:code, ss:stack
start: mov ax, data
mov ds, ax
; display the 'input' string context
lea dx, input
mov ah, 09h
int 21h
; get the buffer_size and input a string
lea dx, buffer_size
mov ah, 0ah
int 21h
; get the actual_size and loop output
mov cl, actual_size
add cl, 0
jnz display
jmp exit_proc
;---------------------
;---------------------
display:
; enter & change line
lea dx, crlf
mov ah, 09h
int 21h
; display 'output' string
lea dx, output
mov ah, 09h
int 21h
; get the string length and set end with '$'
xor cx, cx
mov cl, actual_size
mov dx, offset chars
mov bx, dx
add bx, cx
mov BYTE ptr [bx], '$'
; display the single character
mov ah, 09h
int 21h
;------------------------
;------------------------
exit_proc:
mov ah, 4ch
int 21h
code ends
end start这个是一个 输入一串字符再将其显示出来的代码 为什么我运行后无法输入字符串?; get the buffer_size and input a string
lea dx, buffer_size
mov ah, 0ah
int 21 --
程序代码:stack1 segment para stack 'stack' //stack是关键字,不能做为堆栈段名称
db 1024 dup(?)
stack1 ends
;////////////////////////////////////
data segment para stack 'stack'
input db 'Please input a number:$'
crlf db 0dh, 0ah, '$'
output db 'The result is :$'
;----------------------------
buffer_size db 50 ; max string length = 50
actual_size db ? ; actual string length
chars db 50 dup (20h) ; store from here
data ends
;/////////////////////////////////////////////
code segment
assume ds:data, cs:code, ss:stack1
start: mov ax, data
mov ds, ax
; display the 'input' string context
lea dx, input
mov ah, 09h
int 21h
; get the buffer_size and input a string
lea dx, buffer_size
mov ah, 0ah
int 21h
; get the actual_size and loop output
mov cl, actual_size
add cl, 0
jnz display1
jmp exit_proc
;---------------------
;---------------------
display1: display也不能作为变量名称
; enter & change line
lea dx, crlf
mov ah, 09h
int 21h
; display 'output' string
lea dx, output
mov ah, 09h
int 21h
; get the string length and set end with '$'
xor cx, cx
mov cl, actual_size
mov dx, offset chars
mov bx, dx
add bx, cx
mov BYTE ptr [bx], '$'
; display the single character
mov ah, 09h
int 21h
;------------------------
;------------------------
exit_proc:
mov ah, 4ch
int 21h
code ends
end start这样就ok了

JNZ(或JNE)(jump if not zero, or not equal),汇编语言中的条件转移指令。结果不为零(或不相等)则转移。 格式: JNZ(或JNE) PRO 测试条件:ZF=0那他在这个程序中是什么和什么比较 如果说是cl不为0就跳转 那么没有显示的dec cl 难道是隐含在里面的吗?
