帮忙看看错在哪了(只有五行)

间谍 2003-12-05 02:26:16
.data?

array dd 16 dup(?)
buf db 100 dup(?)


;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;代码段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.code

start:
xor ebx, ebx
inc ebx ;ebx置1
mov edx, 0dh ;edx置13
mov esi, ebx ;头指针
mov edi, edx ;尾指针

;初始化
mov ecx, edx
mov array[ecx], ebx
mov eax, edx
dec ecx
@init:
mov array[ecx], eax
dec eax
loop @init

;计算过程
mov ecx, edx
dec ecx

;删掉了前后无关的代码,问题就在下面这几行,编译通过后,总是非法写地址,我单步调试后,到mov esi, array[edi]这句,array[edi]的值莫名其妙的被更改了,实在搞不懂,大家帮忙看看。
@begin:
push array[esi]
pop array[edi]
mov edi, array[esi]
mov array[esi], ecx
mov esi, array[edi]
loop @begin
...全文
25 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
间谍 2003-12-08
  • 打赏
  • 举报
回复
是啊,果然,我以为都可以像stos一样,可以按需要自动选择呢。谢谢csdsjkk提醒。

还有程序里两个"10"的错误,我也改过来了,谢谢李诚指点。

现在执行起来没问题了。


幸苦二位,马上结贴,希望以后继续关照:)

W32API 2003-12-07
  • 打赏
  • 举报
回复
偶想他的意思是 基址+变址
enzo10 2003-12-07
  • 打赏
  • 举报
回复
楼主能把你的题目说具体点吗??我也想去做做啊~~~~~~~~~~~~~~
csdsjkk 2003-12-07
  • 打赏
  • 举报
回复
楼主显然理解有误,
汇编不是c
间谍 2003-12-07
  • 打赏
  • 举报
回复
dword ptr array[ecx]不是array+ecx*4吗?
那dword ptr array[ecx*4]是什么?
间谍 2003-12-07
  • 打赏
  • 举报
回复
to csdsjkk
把索引寄存器*4以后,还能正确索引到我需要的了吗?

array[ecx] 和 array[ecx*4]是一样的效果?还是我的理解有问题...
间谍 2003-12-07
  • 打赏
  • 举报
回复
谢谢几位,关注中...
W32API 2003-12-07
  • 打赏
  • 举报
回复
???有待分析。。。楼主辛苦。。。我得找个空闲才能再试试
楼上的 csdsjkk() 有空试试嘛。。。
csdsjkk 2003-12-07
  • 打赏
  • 举报
回复
看不懂楼主的程序,
不过偶建议:涉及到访问内存的地方,把索引寄存器 × 4,
象这样:
xxxx[reg * 4]
间谍 2003-12-07
  • 打赏
  • 举报
回复
问题似乎也不是出在这里,因为我不加入wsprintf+messagebox的时候,也一样是非法写  地址。
W32API 2003-12-07
  • 打赏
  • 举报
回复
;*********************************************
pushad
push array[ecx]
push ecx
push offset sz_format_debug
push offset buf
call wsprintf
add esp, 10h

push MB_OK
push offset sz_format_one
push offset buf
push NULL
call MessageBox
popad
;************************************************

你自己调试一下这里的前后堆栈是否对齐。。。
间谍 2003-12-07
  • 打赏
  • 举报
回复
.data?

array dd 1000 dup(?)
buf db 100 dup(?)
.const


sz_format_debug db 'array %d = %d',0

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;代码段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.code

start:
xor ebx, ebx
inc ebx ;ebx置1
mov edx, 0dh ;edx置13
mov esi, ebx ;头指针
mov edi, edx ;尾指针

;初始化
mov ecx, edx
mov array[ecx], ebx
mov eax, edx
dec ecx
@init:
mov array[ecx], eax
dec eax
dec ecx
;*********************************************
pushad
push array[ecx]
push ecx
push offset sz_format_debug
push offset buf
call wsprintf
add esp, 10h

push MB_OK
push offset sz_format_one
push offset buf
push NULL
call MessageBox
popad
;************************************************
test ecx, ecx
jne @init


mov ecx, edx
;*******************************************
@init2:
pushad
push array[ecx]
push ecx
push offset sz_format_debug
push offset buf
call wsprintf
add esp, 10h

push MB_OK
push offset sz_format_one
push offset buf
push NULL
call MessageBox
popad
loop @init2
;*************************************************************


在@init里那个messagebox,是我预期的,array[13]=1,array[i]=array[i+1] (0<i<13)
可紧接着@init2里那个messagebox打出来的,就变成了array[1]=2,其它array[i]=0了,这到底是怎么回事啊?!我想问题就出在这里吧,造成了后面的非法写地址,但我不知道为什么会这样。
W32API 2003-12-07
  • 打赏
  • 举报
回复
我是按照你的计算流程用代码模拟的。我可没时间去推
W32API 2003-12-07
  • 打赏
  • 举报
回复
13 张牌怎么会有两个 10 ?
qass 2003-12-06
  • 打赏
  • 举报
回复
mov array[ecx], eax;很不理解,什么意思?
qass 2003-12-06
  • 打赏
  • 举报
回复
.data?;这个问号是做什么的呢?

array dd 16 dup(?)
buf db 100 dup(?)
间谍 2003-12-06
  • 打赏
  • 举报
回复
up,哪位大哥帮帮忙,郁闷
间谍 2003-12-06
  • 打赏
  • 举报
回复
; 12, 1, 11, 5, 10, 2, 9, 4, 8, 10, 7, 3, 6
的结果就是我希望的,你是怎么得出来的?是推出来的?可是我的程序就是不对,那五行程序我已经看了好几天了,就是找不出毛病来。究竟是怎么回事,我糊涂了。

原题就求一个扑克牌的顺序(规则是拿出一张,再插入队列后一张...)。
W32API 2003-12-06
  • 打赏
  • 举报
回复
@begin:
push array[esi]
pop array[edi]
mov edi, array[esi]
mov array[esi], ecx
mov esi, array[edi]
loop @begin
; array[1 - 13]
; 12, 1, 11, 5, 10, 2, 9, 4, 8, 10, 7, 3, 6
; edi =10, esi = 10, ecx = 0
; 检查你这里,要计算什么的?!!
间谍 2003-12-06
  • 打赏
  • 举报
回复
初始化之后,我用wsprintf+MessageBox打印出的结果不是我预想的(就是你分析的)。只有array[13]=1,array[1]=2,其它的都是array[i]=0 (0<i<13)。

我的程序实际上只有上面几行,计算过程之后就是打印结果了,我贴一下完整的,麻烦你了。


**************************************************************************
.386
.model flat, stdcall
option casemap : none

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;include
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

include e:\masm32\include\windows.inc
include e:\masm32\include\user32.inc
include e:\masm32\include\kernel32.inc
includelib e:\masm32\lib\user32.lib
includelib e:\masm32\lib\kernel32.lib

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;数据段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.data?

array dd 16 dup(?)
buf db 100 dup(?)

.const

sz_result_one db 'the last :,0
sz_format_one db ' %d ',0

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;代码段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.code

start:
xor ebx, ebx
inc ebx ;ebx置1
mov edx, 0dh ;edx置13
mov esi, ebx ;头指针
mov edi, edx ;尾指针

;初始化
mov ecx, edx
mov array[ecx], ebx
mov eax, edx
dec ecx
@init:
mov array[ecx], eax
dec eax
loop @init

;计算过程
mov ecx, edx
dec ecx

@begin:
push array[esi]
pop array[edi]
mov edi, array[esi]
mov array[esi], ecx
mov esi, array[edi]
loop @begin

pushad
push esi
push offset sz_format_one
push offset buf
call wsprintf
add esp, 0ch

push MB_OK
push offset sz_result_one
push offset buf
push NULL
call MessagBox
popad



push NULL
call ExitProcess

end start
加载更多回复(4)

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧