The MASM Forum

General => The Campus => Topic started by: stevenxie on December 01, 2020, 11:26:34 PM

Title: Dup instruction defines array test specimens
Post by: stevenxie on December 01, 2020, 11:26:34 PM
hi,everyone.
   this is a dup instruction defines array test speciens.

include \masm32\include64\masm64rt.inc     ;加载MASM64 SDK主预处理器包含

.data
      val00 qword 3 dup(54*24)
      val01 BYTE 20 DUP ( 65 )             ;20 个字节,值都为 0
      val02 BYTE 20 DUP ( ? )              ;20 个字节,非初始化
      str01 BYTE 4 DUP ( "STACK" ),0       ; 23 个字节
      str02 BYTE 4 DUP ( "STACK",0)        ; 20 个字节
      str03 BYTE 4 DUP ( "STACK",32 ),0    ; 23 个字节
      counter byte 0                        ;作为循环条件计数器

.code
      entry_point proc
    ;*******************循环体*********************************
        lb1:                                                  ;循环体开始首标签
           cmp counter,3                                      ;循环条件计数器counter与数组val00的dup整数计数器值3进行条件比较
           je lb2                                             ;判断如果counter值等于dup整数计数器值3,则无条件转移至下一个标签lb2,跳出循环体
           mov rax,qword ptr val00                            ;将数组内存地址及偏移量推送入中央处理器64位易失性寄存器rax中
           conout tab,str$(rax),tab                           ;调用控制台显示功能宏conout,屏幕依次显示数组val00内的各数组元素值
           mov rax,[qword ptr val00]+8                        ;数组元素指针增加8字节,指向下一个数组元素内存地址
           add counter,1                                      ;循环条件计数器counter值自动加一
           jmp lb1                                            ;只要循环判断条件成立,无条件转移至首标签lb1,继续执行循环体
    ;*******************循环体*********************************
        lb2:
           conout lf
           conout tab,tab, "&"
           conout lf
           conout tab,tab
           stdout addr val01               ;注意显示的结果
           conout lf
           conout tab,tab,"*"
           conout lf
           conout tab,tab
           stdout addr str01               ;注意显示的结果
           conout lf
           conout tab,tab
           stdout addr str02               ;注意显示的结果
           conout lf
           conout tab,tab
           stdout addr str03               ;注意显示的结果

           conout lf,tab,tab
           waitkey
         
         .exit

      entry_point endp
end
Title: Re: Dup instruction defines array test specimens
Post by: hutch-- on December 02, 2020, 12:44:31 AM
This looks like it works OK. I can read the comments but the basic logic is sound.
Title: Re: Dup instruction defines array test specimens
Post by: jj2007 on December 02, 2020, 02:29:35 AM
Finally a well-commented source :thumbsup:
Title: Re: Dup instruction defines array test specimens
Post by: LordAdef on December 13, 2020, 10:34:39 AM
Your second comment seems a bit ambiguos  :skrewy: :skrewy: :skrewy: