贺利坚老师汇编实验五

任务1-求最大值

在BUFFER处给出了多个无符号数,请找出其中的最大值,放至MAX指定的存储单元中。

data  segment

  buffer dw 35098, 17758, 54582, 61504, 46054, 58513, 4409, 7902, 14255

         dw 40623, 47645, 15575, 51572, 18110, 26511, 14880, 5921, 31999

         dw 2893, 21056, 16574, 147, 25532, 33336, 5251, 64269, 31514, 23670

         dw 53335, 49581, 57895, 25689, 51697, 58198, 27548, 54151, 41373

         dw 44382, 23511, 39326, 56955, 51911

  max dw  ?

data  ends

已知标号为BUFFER的数组后直接就是标号为MAX的单元,数组中元素的个数由程序计算,不得人工数。给定的数据中,最大者为64269(FB0DH)。

assume ds:data,cs:codesg

data  segment
  buffer dw 35098, 17758, 54582, 61504, 46054, 58513, 4409, 7902, 14255
         dw 40623, 47645, 15575, 51572, 18110, 26511, 14880, 5921, 31999
         dw 2893, 21056, 16574, 147, 25532, 33336, 5251, 64269, 31514, 23670
         dw 53335, 49581, 57895, 25689, 51697, 58198, 27548, 54151, 41373
         dw 44382, 23511, 39326, 56955, 51911
  max dw  ?
data  ends

codesg segment
start: mov ax,data
       mov ds,ax
       mov cx,offset max-offset buffer ;Subtract the offset address to find the range of the loop.
       shr cx,1 ;Because it is stored by the word, the actual number is only half,
       ;and the operation of dividing by 2 is performed by logically shifting one bit to the right.
       mov bx,offset buffer
       mov ax,ds:[bx] ;Assume that the first number is the largest.
       mov bx,2
       dec cx ;Remove one cycle.

   s0: cmp ax,ds:[bx] ;Subtract the comparison size by cmp instruction.
       jae next ;If it is greater than or equal to 0, jump.
       mov ax,ds:[bx] ;If less then update the value of ax.

 next: add bx,2 ;Compare the next number.
     loop s0
       
       mov bx,offset max
       mov ds:[bx],ax ;Place the maximum ax in the required position.

       mov ax,4c00h
       int 21h
codesg ends
end start

任务2-成绩统计

下面提供了100名同学AS课成的成绩,请编程序统计其中90~100、60~89、60以下者各有多少人?并把结果连续存放到自RESUT开始的单元中。

assume ds:data,cs:code
data segment
   buf db 85, 72, 79, 90, 79, 54, 63, 66, 83, 79, 71, 77, 77, 65, 89, 93
       db 69, 96, 72, 98, 60, 78, 69, 68, 80, 65, 91, 64, 90, 90, 64, 90
       db 99, 55, 84, 56, 80, 54, 55, 66, 53, 54, 83, 61, 52, 92, 66, 51
       db 95, 81, 51, 100, 70, 65, 50, 74, 91, 57, 95, 66, 54, 50, 73, 59
       db 78, 80, 92, 78, 89, 78, 99, 100, 82, 92, 59, 71, 74, 81, 93, 74
       db 98, 57, 57, 96, 76, 79, 57, 67, 52, 84, 87, 54, 67, 72, 59, 75
       db 64, 89, 77, 80
result  db 3 dup(0)
data ends

code segment
start: mov ax,data
       mov ds,ax
       mov cx,100
       mov bx,offset buf   ;Get the offset address at buf.
    s0:cmp byte ptr[bx],90
       jb  first           ;Less than jumps.
       inc [result]        ;The result is placed in the first position at the beginning of the result.
       jmp third           ;End a screening.
 first:cmp byte ptr[bx],60
       jb  second
       inc [result+1]
       jmp third
second:inc [result+2]
       jmp third
 third:inc bx             ;Perform the next screening.
     loop s0
       mov ax,4c00h
       int 21h
code ends
end start

任务3-保留字符串中的大写字母

在数据区,给定用0作为结束的字符串,请补充完成子程序,只保留字符串中的大写字母,并在最后一个大写字母后记录0作为所有大写字母构成的新字符串的结束。(以下面程序数据区中给出的字符串,最后得到的字符串为YTU后加0)

assume cs:cseg, ds:dseg, ss:sseg

sseg   segment  stack

    dw  100h  dup  (?)

sseg   ends

dseg   segment

    db 'YanTai University 264005', 0

dseg   ends

cseg   segment

start: mov  ax, dseg

       mov  ds, ax

       mov  ax, sseg

       mov  ss, ax

       mov  sp, 100h

 

       mov bx, 0

       call getUpper

 

       mov  ax, 4c00h

       int   21h

 

;子程序名:getUpper

;功    能:对从DS:bx开始,以0结束的字符串,只保留大写字母,并仍以0结束

;入口参数:DS和BX寄存器中保存字符串的起始地址

;出口参数:无

getUpper  proc

          ; 请写出你的代码

          ret

getUpper  endp

cseg  ends

      end   start

assume cs:cseg, ds:dseg, ss:sseg
dseg   segment
    db 'YanTai University 264005', 0
dseg   ends
sseg   segment  stack
    dw  100h  dup  (0)
sseg   ends
cseg   segment
start: mov  ax, dseg
       mov  ds, ax
       mov  ax, sseg
       mov  ss, ax
       mov  sp, 100h

       mov bx, 0
       call getUpper

       mov  ax, 4c00h
       int   21h

;子程序名:getUpper
;功    能:对从DS:bx开始,以0结束的字符串,只保留大写字母,
;并仍以0结束
;入口参数:DS和BX寄存器中保存字符串的起始地址
;出口参数:无
getUpper  proc
          push ax
          push si ;Before the function starts, all the registers used are pushed onto the stack.
	  mov si,bx
 again:   mov al,ds:[si]
	  or al,al ;The loop is controlled by judging 0.
	  jz  ok     ;Equal to the jump.
	  cmp al,'A' 
	  jb  next   ;Jump less than A.
          cmp al,'Z'
          ja  next       ;Jump greater than Z.
	  jmp next2
  next:   mov byte ptr ds:[si],0
 next2:   inc si      ;Continue scanning the next character.
          jmp again
    ;ok:   mov [si],cl ;Set to 0 at the end of the store.
    ok:   pop ax
	  pop si   ;After finishing, all registers are popped.
          ret
getUpper  endp
cseg  ends
      end   start

任务4:冒泡排序(选做)

  在数据区,给出了学生人数及汇编语言课程的成绩,请将成绩排序并保存在原数据区。

报告内容:程序及运行结果如下(已经加入了足量的注释)

assume cs:cseg, ds:dseg, ss:sseg
dseg segment
    db 20
    db 98,61,57,82,89,73,61,58,53,54
    db 84,78,70,64,84,63,76,84,83,86
dseg ends
sseg segment  stack
    dw 100H dup (?)
sseg ends
cseg segment
  start: mov ax, dseg
         mov ds, ax
         mov cl, ds:[0]
         mov ch, 0      ;cx中存储要排序数的个数
         mov bx, 1      ;要排序数的起始偏移地址
         call sort

         mov ax, 4c00h
         int   21h
;子程序名:sort
;功    能:对从(DS):(bx)开始的(cx)个字节排序
;入口参数:(DS):(BX)保存数据的起始地址
;        (cx)中是要排序的数据个数
;出口参数:无
sort proc
   push bx
   push ax
   push cx
   dec cx
   s:                     ;for(int i=0;i<19;i++)
       push cx
       mov bx,1
	 s0:                ;for(int j=0;j<19-i-1;j++)
	    mov al,ds:[bx]
	    cmp al,ds:[bx+1]
	    jbe next            ;if(a[j]<a[j+1])
	    xchg al,[bx+1]      ;swap(a[j],a[j+1])
	    mov [bx],al
	    next:inc bx         ;j++
	 loop s0
	    pop cx
   loop s
    pop bx
    pop ax
    pop cx
    ret
sort endp
cseg ends
end start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值