实验5 第6题的问题,大家帮忙看看。谢谢
本帖最后由 xxasy 于 2011-6-27 09:44 编辑6. 程序如下,编写code段中的代码,用push指令将a段中的word数据,逆序存储到b段中。
assume cs:codea segmentdw 1,2,3,4,5,6,7,8a ends b segmentdw 0,0,0,0,0,0,0,0b endscode segmentstart: mov ax,a
mov ds,ax
mov ax,b
mov ss,ax
mov sp,0
add sp,20h
mov bx,0
mov cx,8
s: push ds:
inc bx
loop s mov ax,4c00h int 21hcode ends
end start
这样写对么?求大牛指点一二。万分感谢.
不对,既然是word型数据,那就是inc bx两回 也就是说 要改成add bx,2咯? 本帖最后由 king嗜血法师 于 2011-6-27 07:30 编辑
肯定错了,你把B数据段当成栈,那sp不可能是从0开始的,bx也不能从0开始。
mov sp,16
mov bx,14
所以bx不是加2,而是减2
sub bx,2
栈是逆方向存储的,那数据也应该逆方向索引。 其实你把a做栈,b做数据,效果会好很多。
mov ax,b
mov ds,ax
mov ax,a
mov ss,ax
这样的话sp和bx就能从0开始了
mov sp,0
mov bx,0
mov cx,8
s: pop ds:
add bx,2
loop s
pop是顺方向释放的,这样效果就好的多。 多谢指教,但是题目是让用push指令啊。 assume cs:code,ds:a,ss:b
a segment
dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0eh,0fh,0ffh
a ends
b segment
dw 0,0,0,0,0,0,0,0
b ends
code segment
start: mov ax,b
mov ss,ax
mov sp,16
mov ax,a
mov ds,ax
push ds:
push ds:
push ds:
push ds:
push ds:
push ds:
push ds:
push ds:
mov ax,4c00h
int 21h
code ends
end start
我这样写,感觉有问题,调试看到栈类容,只PUSH了1,2,3,4,5,6.而7,8既然没有,不知道是何缘故.请知道的帮助解释一下. 是我弄错了```做过的题目自己忘了。
是把a的1-8放成b的8-1,是我的错,把题目看错了。
把mov sp,0 改成 mov sp,16在把inc bx改成add bx,2就行了,我的错.....
页:
[1]