汇编语言-实验5
本帖最后由 Push 于 2012-1-23 22:03 编辑题目:把a、b段依次相加,结果存放c中.
这样写通不通?
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
c segment
dw 0,0,0,0,0,0,0,0
c segment
code segment
start: mov ax,a
mov ss,ax
mov sp,16
mov dx,c
mov bx,0
mov cx,8
s: push dx:
add bx,2
loop s
mov ax,b
mov bx,0
mov cx,8
s1: add dx:,ax
add bx,2
loop s1
code ends
end start
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,b
mov es,ax
mov bx,0
mov cx,8
s: mov al,
mov ah,0
add es:,al
inc bx
loop s
mov ax,d
mov ds,ax
mov ax,b
mov es,ax
mov bx,0
mov cx,8
s1:mov al,es:
mov ds:,al
inc bx
loop s1
mov ax,4c00h
int 21h
code ends
end start
看了下别人的,改了我的下,借我觉得写程序的时候AX在LOOP里面要清零,可以少错误吧。想了,不过没去试,不知你现在还要不要。{:1_1:} 好像循环次数弄错了,改成16...大家继续解答 好像就是8哦...混乱中,大家将就看看吧... c segment
db 0,0,0,0,0,0,0,0
c segment
这要能通才怪。
而且MASM里面“c”是保留字符。
你自己最起码要编译下…… 第二个c segment
mov dx,c s:
push dx:
s1: add dx:,ax
错误太多,自己编译看一下
本帖最后由 Push 于 2012-1-24 16:50 编辑
这么改行不行
assume cs:code
datasg segment
db 1,2,3,4,5,6,7,8
datasg ends
esg segment
db 1,2,3,4,5,6,7,8
esg ends
stacksg segment
db 0,0,0,0,0,0,0,0
stacksg segment
code segment
start: mov ax,stacksg
mov ss,ax
mov sp,16
mov ax,datasg
mov ds,ax
mov bx,0
mov cx,8
s: push bx
inc bx
loop s
mov ax,esg
mov ds,ax
mov cx,8
s1: add al,ds:
inc bx
loop s1
mov ax,4c00h
int 21h
code ends
end start 第10行的stacksg segment错了
实在看不出第19—21行的循环有什么意义
是在把0到7推进栈吗?
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,b
mov es,ax
mov bx,0
mov cx,8
s: mov bl,
mov bh,0
add es:,bl
inc bx
loop s
mov ax,d
mov ds,ax
mov ax,b
mov es,ax
mov bx,0
mov cx,8
s1:mov bl,es:
mov ds:,bl
inc bx
loop s1
mov ax,4c00h
int 21h
code ends
end start
给你看我的,不过我的这个好像也有错。郁闷,偏移位置加起来的就不对,还要整 assume cs:code
data segment
db 1,2,3,4,5,6,7,8
db 1,2,3,4,5,6,7,8
dw 0,0,0,0,0,0,0,0
data ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov si,8
mov di,16
mov cx,8
mov ax,0
s: mov al,
add al,ds:
mov ds:,ax
inc bx
inc si
add di,2
loop s
mov ax,4c00h
int 21h
code ends
end start
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
c segment
db 0,0,0,0,0,0,0,0
c ends
code segment
start:mov cx,8
mov bx,0
s:mov ax,a
mov ds,ax
mov ax,0
mov al,
mov dl,al
mov ax,b
mov ds,ax
mov ax,0
mov al,
add dl,al
mov ax,c
mov ds,ax
mov ,dl
inc bx
loop s
mov ax,4c00h
int 21h
code ends
end start
我的思路:
1.把数据段ds 指向数据段a, es指向数据段c
2.a里的值依次和c里的值相加,结果存入c
3.再将ds指向数据段b,b里的值在依次和C里的数据相加,结果仍然存在C里
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
c segment
db 0,0,0,0,0,0,0,0
c ends
code segment
start: mov ax,a
mov ds,ax
mov bx,0
mov ax,c
mov es,ax
mov cx,8
s: mov ax,0
mov al,
add es:,al
inc bx
loop s
mov ax,b
mov ds,ax
mov bx,0
mov cx,8
s0: mov ax,0
mov al,
add es:,al
inc bx
loop s0
mov ax,4c00H
int 21H
code ends
end start
页:
[1]