【问题标题】:Length of input string in assembly language汇编语言中输入字符串的长度
【发布时间】:2013-10-24 03:31:49
【问题描述】:

我想做两件事:
1) 从用户获取一个字符串
2) 找出那个字符串的长度

我尝试了以下代码:

.model small    
.stack 100h
.data
    MAXLEN DB 100
    ACT_LEN DB 0                ;Actual length of the string  
    ACT_DATA DB 100 DUP('$')    ;String will be stored in ACT_DATA
    MSG1 DB 10,13,'ENTER STRING : $'
.CODE
START:
    MOV AX,@data
    MOV DS,AX
    ;Normal printing 
    LEA DX,MSG1
    MOV AH,09H
    INT 21H
    ;Cant understand code from here!
    LEA DX,ACT_DATA
    MOV AH,0AH
    MOV DX,OFFSET MAXLEN
    INT 21H

    LEA SI,ACT_DATA
    MOV CL,ACT_LEN

    ;AND THEH SOME OPERATIONS

END START

但我很困惑长度是如何存储在CL 寄存器中的,即ACT_LEN 值是如何递增的? mov AH,0A 与长度究竟有什么关系?

【问题讨论】:

    标签: string assembly x86 dos


    【解决方案1】:

    Int 21/AH=0Ah

    Format of DOS input buffer:
    
    Offset  Size    Description     (Table 01344)
    00h    BYTE    maximum characters buffer can hold (MAXLEN)
    01h    BYTE    (call) number of chars from last input which may be recalled (ACT_LEN)
    (ret) number of characters actually read, excluding CR
    02h  N BYTEs   actual characters read, including the final carriage return (ACT_DATA)
    

    缓冲的输入中断会填充这些值。

    LEA DX,ACT_DATA
    MOV AH,0AH
    MOV DX,OFFSET MAXLEN
    INT 21H
    

    你不需要LEA DX,ACT_DATA

    mov AH,0A 是要调用的中断号。 Ralph Brown has a big list 带有描述的中断以及输入/输出的内容。

    【讨论】:

    • ACT_LEN 值是如何改变的。对不起,我没听明白!这一切都是通过指令 MOV AH,0Ah 偏移 01h 完成的吗??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多