Push 发表于 2012-1-23 12:32:44

汇编语言实验5(6)

那这题写的有错不 ?
题目:将a段的前8个数据逆序存放到b中.
assume cs:code
a segment
dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
a ends
b segment
dw 0,0,0,0,0,0,0,0
b ends
code segment
start: mov ax,a
mov ds,ax
mov bx,16
mov ss,dx
mov sp,16
mov bx,0
mov cx,8
s: push ss:
sub bx,2
loop s
code ends
end start

仰望天上的光 发表于 2012-1-23 12:32:45

本帖最后由 仰望天上的光 于 2012-1-23 14:57 编辑

1.要用堆栈存放数据,所以段b应该为堆栈段。但你的程序中没有:
mov ax,b
mov ss,ax
mov sp,16
这样的语句
2.循环体大概要如下:
mov bx,0
mov cx,8
s: push ds:
   add bx,2
   loop s

liyangsj 发表于 2012-1-23 13:45:46

sub bx,2    不是减   是ADD

Push 发表于 2012-1-23 14:02:27

liyangsj 发表于 2012-1-23 13:45 static/image/common/back.gif
sub bx,2    不是减   是ADD

是逆向啊,我先定义到偏移地址16啊...那复制了08这个字节的内容,粘贴到B了,是不是要到A段中退2个偏移地址再复制7呢?是逆序逆序,不是顺序

Push 发表于 2012-1-23 19:46:37

仰望天上的光 发表于 2012-1-23 14:57 static/image/common/back.gif
1.要用堆栈存放数据,所以段b应该为堆栈段。但你的程序中没有:
mov ax,b
mov ss,ax


你说的我写的里面都有啊...看清楚些...然后帮我看看有没有错

仰望天上的光 发表于 2012-1-23 21:26:56

Push 发表于 2012-1-23 19:46 static/image/common/back.gif
你说的我写的里面都有啊...看清楚些...然后帮我看看有没有错

比如我写的:
mov ax,b
mov ss,ax
在你程序里没有出现,你的程序仅仅将SS设置为DX(天晓得DX的初始值是什么)

并且你写的是push ss:
我写的是push ds:这两句是不一样的
你写的是sub bx,2(BX初始值已经为0了,还不断的减2)
我写的是 add bx,2

所以我写的基本都是你没有写的

Push 发表于 2012-1-23 22:26:24

仰望天上的光 发表于 2012-1-23 21:26 static/image/common/back.gif
比如我写的:
mov ax,b
mov ss,ax


哦,那么完整的是怎么样的?...还有实验5的答案我也不知道...课后习题实验五答案不在网站上

IV小叮当 发表于 2012-1-24 12:38:22

牛!!!!!!!!!!

Push 发表于 2012-1-24 17:18:45

这样可以么?assume cs:code,ds:a,ss:b
data segment
        dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
data ends
stack segment
        dw 0,0,0,0,0,0,0,0
stack ends
code segment
start:mov ax,data
        mov ds,ax
        mov ax,stack
        mov ss,ax
        mov sp,16
        mov bx,16
        mov cx,8
s:        push bx
        sub bx,2
        loop s
        mov ax,4c00h
        int 21h
code ends
end start

tangqy 发表于 2012-1-29 11:29:30

assume cs:code
a segment
dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
a ends

b segment
dw 0,0,0,0,0,0,0,0
b ends

code segment
   start: mov ax,a
         mov ds,ax
         mov ax,b
         mov ss,ax
         mov sp,16
                  
            mov bx,0
            mov cx,8
         
          s:push ds:
            add bx,2
            loop s
         mov ax,4c00h
         int 21h
code ends
end start


试一下我上边的代码,应该可以。
页: [1]
查看完整版本: 汇编语言实验5(6)