| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 504 人关注过本帖
标题:汇编做的小程序无法运行 数组插入元素
只看楼主 加入收藏
剑飘香
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-9-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
汇编做的小程序无法运行 数组插入元素
数组插入元素

DATAS SEGMENT
  x dw ?
  array_head dw 3,5,15,23,37,49,52,65,78,99
  array_end dw 105
  n dw 32
DATAS ENDS

CODES SEGMENT

main proc far
  ASSUME CS:CODES,DS:DATAS
START:
  MOV AX,DATAS
  MOV DS,AX
  mov ax,datas
  mov ds,ax
  mov cx,11
  call print
  mov ax,n
  mov x,0ffffh
  mov si,0
compare:
  cmp array_end[si],ax
  jle insert
  mov bx,array_end[si]
  mov array_end[si+2],bx
  sub si,2
  jmp short compare
insert:
  mov array_end[si+2],ax
  mov cx,12
  call print
  ret
main endp

print proc near
  pop cx
  push ax
  push dx
  push si
  mov si,0
again:
  mov ax,array_head[si]
  mov dl,10
  div dl
  add al,30h
  add ah,30h
  mov dh,ah
  mov dl,al
  mov ah,2
  int 21h
  mov al,dh
  mov dl,al
  mov ah,2
  int 21h
  mov dl,08h
  mov ah,2
  int 21h
  add si,2
  loop again
  pop si
  pop dx
  pop ax
  ret
print endp
   
CODES ENDS
  END START
搜索更多相关主题的帖子: insert 元素 
2011-11-24 23:08
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:20 
程序代码:
data segment
  x          dw ?
  array_head dw 3,5,15,23,37,49,52,65,78,99    ;short int array_head[10] = {3,5,15,23,37,49,52,65,78,99};
  array_end  dw 105              ;short int array_end = 105;
  n          dw 32               ;short int n = 32;
data ends

code segment
      main proc far
      assume cs:code, ds:data
start:
      mov ax,data
      mov ds,ax
      mov cx,11                  ;short int length = 11;
      call print                 ;print(length);
      mov ax,n
      mov x,0ffffh               ;x = -1; not use ?
      mov si,0                   ;i = 0;
compare:
      cmp array_end[si],ax
      jle insert                 ;if (array_end[i] <= n) goto insert;
      mov bx,array_end[si]
      mov array_end[si+2],bx     ;else array_end[i+2] = array_end[i];
      sub si,2                   ;i -= 2;
      jmp short compare          ;goto compare;
insert:
      mov array_end[si+2],ax     ;array_end[i+2] = n;
      mov cx,12                  ;length = 12;
      call print                 ;print(length);
      ret
    main endp

    print proc near
      pop cx                     ;j = get return address from stack ?
      push ax
      push dx
      push si                    ;short int a, b, i;
      mov si,0                   ;i = 0;
again:
      mov ax,array_head[si]      ;a = array[i];
      mov dl,10               
      cbw
      div dl                     ;a /= 10;
      add al,30h
      add ah,30h                 ;a += 0x3030;
      mov dh,ah
      mov dl,al                  ;b = a;
      mov ah,2
      int 21h
      mov al,dh
      mov dl,al
      mov ah,2
      int 21h                    ;putchar(HIBYTE(a));putchar(LOBYTE(a));
      mov dl,08h
      mov ah,2
      int 21h                    ;printf("\b");
      add si,2                   ;i += 2;
      loop again                 ;while (j--);
      pop si
      pop dx
      pop ax                     ;release local variable
      ret
    print endp
code ends
end start
红色标注的地方,你再想想

技术问题,请不要以短消息方式提问
2011-11-25 10:15
快速回复:汇编做的小程序无法运行 数组插入元素
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012782 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved