8086汇编中数组元素读取至AL寄存器异常问题求助
8086汇编数组访问问题:输入字符的ASCII值与预期数值不符
我在8086汇编中尝试访问用户输入的数组(输入值为12134),每次迭代将数组元素存入AL寄存器。但在arr_acc过程中,第一个元素存入AL的值为31,第二个为32,和预期的1、2不符。已尝试用SI替代DI、直接自增BX的方法,问题仍未解决。
相关代码如下:
;read and access array DIM EQU 5 .MODEL small .STACK .DATA arr DB DIM DUP(?) .CODE .STARTUP MOV BX, OFFSET arr ;Storing the address of arr to bx CALL READ ; Calling the read procedure to input data into arr MOV BX, OFFSET arr ;Storing the address of arr to bx CALL arr_acc ;Calling the procedure that should access each element of the array and store each element ;in AL with every iteration .EXIT ; PROCEDURES ; Read PROC MOV DI, 0 MOV AH, 1 ; set AH for reading lab1: INT 21H ; read a character MOV BX[DI], AL ; store the character INC DI ; go to next element CMP DI, DIM ; compare array index with 0 JNE lab1 ; jump if not equal RET Read ENDP arr_acc PROC MOV AX,0 MOV DI,0 lop: CMP DI,DIM ; checking if the DI reached the maximum index DIM JE EXIT_LOP ;exit the lop which will exit the procedure as well MOV AL, BX[DI] ; Moving the first element in AL INC DI ; increment DI to get to the next element JMP lop ; jump back to the loop EXIT_LOP: RET arr_acc ENDP END
尝试的解决方法:
- 使用SI寄存器替代DI
- 仅使用BX并按1自增(因数组为字节类型)
内容的提问来源于stack exchange,提问作者Mohamed Khaled
相关产品推荐
相关产品推荐

