1、org 100h
mov dx, offset buffer
mov ah, 0ah
int 21h
jmp print
buffer db 10,?, 10 dup(' ') //第一个是缓冲的长度(人为设置)、第二个是实际读入的字符的数量(电脑根据实际输入的字符个数自动设置)、第三个开始存储字符。
print:
xor bx, bx
mov bl, buffer[1]
mov buffer[bx+2], '$'
mov dx, offset buffer + 2
mov ah, 9
int 21h
ret
2、0a号功能使用错误。
接受输入字符串缓冲区的定义说明:
1、第一个字节为缓冲区的最大容量,可认为是入口参数;
2、第二个字节为实际输入的字符数(不包括回车键),可看作出口参数;
3、从第三个字节开始存放实际输入的字符串;
BUF DB 30,0,30 DUP(?)
然后就是0a号功能不是以$作为字符串结尾的,所以应该自己手动加上,这样使用9号功能的时候才不会出错。
3、div / idiv 指令。
AX 存放 目的操作数。运算后 对于字节操作 AH存放模 ,AL 存放商。
Eg:
Unsigned divide.
Algorithm:
when operand is a byte:
AL = AX / operand
AH = remainder (modulus)
when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
Example:
MOV AX, 203 ; AX = 00CBh
MOV BL, 4
DIV BL ; AL = 50 (32h), AH = 3
RET
Example:
MOV AX, -203 ; AX = 0FF35h
MOV BL, 4
IDIV BL ; AL = -50 (0CEh), AH = -3 (0FDh)
RET
4、mul / imul
when operand is a byte:
AX = AL * operand.
when operand is a word:
(DX AX) = AX * operand.
Example:
MOV AL, 200 ; AL = 0C8h
MOV BL, 4
MUL BL ; AX = 0320h (800)
RET
C | Z | S | O | P | A |
r | ? | ? | r | ? | ? |
CF=OF=0 when high section of the result is zero.
when operand is a byte:
AX = AL * operand.
when operand is a word:
(DX AX) = AX * operand.
Example:
MOV AL, -2
MOV BL, -4
IMUL BL ; AX = 8
RET
C | Z | S | O | P | A |
r | ? | ? | r | ? | ? |
CF=OF=0 when result fits into operand of IMUL.