注册 登录
编程论坛 汇编论坛

汇编输入一个数 再显示这个数?

有容就大 发布于 2012-05-25 13:36, 1382 次点击
我的意图是输入一个数后 ENTER 程序马上再显示这个数出来
貌似0-9可以用 SUM AL 30H来搞 2位 3位 多位的数怎么弄 是不是要存在一个字符数组里然后 通过单个字符转换
为数字 并循环输出?

有没有其他的方法?
12 回复
#2
有容就大2012-05-25 14:46
程序代码:
;//////////////////////////////////
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  
--
这个中断调用没起作用啊 为什么?

只有本站会员才能查看附件,请 登录

诚心求教!

[ 本帖最后由 有容就大 于 2012-5-25 15:21 编辑 ]
#3
于祥2012-05-25 20:48
程序代码:
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了
#4
有容就大2012-05-25 21:35
回复 3楼 于祥
非常感谢你帮我解答 原来这样
这个是我看资料 凑合的 还是对一些东西理解不透 比如JNZ 网上介绍的不怎么深入
 JNZ(或JNE)(jump if not zero, or not equal),汇编语言中的条件转移指令。结果不为零(或不相等)则转移。   格式: JNZ(或JNE) PRO   测试条件:ZF=0
那他在这个程序中是什么和什么比较 如果说是cl不为0就跳转 那么没有显示的dec cl 难道是隐含在里面的吗?

还有个问题 下面是我运行这个程序的过程
只有本站会员才能查看附件,请 登录


每运行一次程序都要输入他的绝对路径吗 我把程序放在了D:\masm\11\dis里 那要是一个超长的路径每次输入很麻烦啊 有没有简单的方法?
#5
zklhp2012-05-26 13:19
以下是引用有容就大在2012-5-25 21:35:32的发言:

非常感谢你帮我解答 原来这样
这个是我看资料 凑合的 还是对一些东西理解不透 比如JNZ 网上介绍的不怎么深入  JNZ(或JNE)(jump if not zero, or not equal),汇编语言中的条件转移指令。结果不为零(或不相等)则转移。   格式: JNZ(或JNE) PRO   测试条件:ZF=0那他在这个程序中是什么和什么比较 如果说是cl不为0就跳转 那么没有显示的dec cl 难道是隐含在里面的吗?

还有个问题 下面是我运行这个程序的过程


每运行一次程序都要输入他的绝对路径吗 我把程序放在了D:\masm\11\dis里 那要是一个超长的路径每次输入很麻烦啊 有没有简单的方法?

到那个目录里就是了呗
#6
有容就大2012-05-26 14:31
以下是引用zklhp在2012-5-26 13:19:46的发言:


切到那个目录里就是了呗
怎么切啊 z版 还拿不稳刀 。不过我现在有个办法就是把路径复制后再黏贴 但是这个只是对于一个路径有效多个路径就又麻烦了,能比划下切的动作吗?
#7
zklhp2012-05-26 15:42
我的意思就是cd到那个目录里 至于多个目录么 可以用历史命令 cmd里就是上下方向键 比再打容易一些
#8
有容就大2012-05-26 16:43
回复 7楼 zklhp
哦 原来这样啊 谢谢啦
#9
于祥2012-05-26 20:02
回复 4楼 有容就大
JNZ和JNE就是判断标志位ZF是不是为0的转移指令,你上边的指令有可能会影响ZF标志位,不一定就的DEC指令才行


我们的编译器是老师给的,我没用过其他的
#10
有容就大2012-05-26 20:26
回复 9楼 于祥
看来还的慢慢学习 还不清楚影响ZF标志位的一些东西是什么。
#11
于祥2012-05-27 09:34
回复 10楼 有容就大
我也就学了一点儿了,暑假的时候的多看看了!
#12
powlin19912012-05-27 21:33
回复 7楼 zklhp
是不是可以在cmd下输入一个path的命令,然后就可以直接进行编译该路径下的asm文件,貌似这个还是挺方便的啦。
#13
zklhp2012-05-28 11:52
以下是引用powlin1991在2012-5-27 21:33:05的发言:

是不是可以在cmd下输入一个path的命令,然后就可以直接进行编译该路径下的asm文件,貌似这个还是挺方便的啦。

这个也很好 一般编译器都得加到path里
1