|
发表于 2018-1-28 12:03:38
|
显示全部楼层
本帖最后由 cnkizy 于 2018-1-28 12:38 编辑
- assume cs:code
- a segment
- db 1, 2, 3, 4, 5, 6, 7, 8
- a ends
- b segment
- db 1, 2, 3, 4, 5, 6, 7, 8
- b ends
- d segment
- db 0, 0, 0, 0, 0, 0, 0, 0
- d ends
- code segment
- start: mov ax, a
- mov ds, ax
- mov ax, d
- mov es, ax
-
- mov bx, 0
- mov cx,8
-
- s: mov ax, ds:[bx]
- mov es:[bx],ax
- inc bx
- loop s
-
- mov ax, b
- mov ds, ax
-
- mov bx, 0
-
- mov cx,8
-
- s1: mov ax, ds:[bx]
- add es:[bx],ax
- inc bx ;你用的是16位寄存器,这里应该+2 而不是+1 所以这里应该是 add bx,2
- loop s1
- mov ax, 4c00h
- int 21h
- code ends
- end start
复制代码
inc bx的结果
add bx,2的结果
你用的是16位寄存器bx 这里要加2,如果你非要用inc指令也不是不可以,那得换成bh或者bl
16位寄存器每次读取两个字节,你偏移的时候也应该加上2,inc bx 是加1的意思。
上面那个其实也应该用8位寄存器才对,因为数据是db类型,然后你的inc reg就对了
如下:
- code segment
- start: mov ax, a
- mov ds, ax
- mov ax, d
- mov es, ax
-
- mov bx, 0
- mov cx,8
-
- s: mov al, ds:[bx]
- mov es:[bx],al
- inc bx
- loop s
-
- mov ax, b
- mov ds, ax
-
- mov bx, 0
-
- mov cx,8
-
- s1: mov al, ds:[bx]
- add byte ptr es:[bx],al
- inc bx ;这里用的是8位寄存器 al,所以inc bx就对了
- loop s1
- mov ax, 4c00h
- int 21h
- code ends
复制代码
|
|