汇编语言简单程序

时间:2015-05-12 10:12:11

标签: assembly

我必须用汇编语言为H8S编写一个简单的程序。用户输入50个uint16号码,在每个号码后,程序应对所有输入的号码进行排序并打印出来。我如何实现像Array这样的东西并使用它?

        .text
        .global _start

_start:
        mov.l   #stck,ER7           
        xor.l   ER6,ER6             

begin:
         inc.l  #1,ER6                                      
        mov.w   #PUTS,R0            
        mov.l   #par_o,ER1          
        jsr     @syscall

        mov.w   #GETS,R0            
        mov.l   #par_i,ER1          
        jsr     @syscall

        jsr     @insert
        jsr     @sort
        jsr     @write

        cmp.l   #50,ER6
        bcs     begin
        jmp     @end


insert:
        rts


sort:   
        rts

write:  
        rts


end:    


        jmp @end

1 个答案:

答案 0 :(得分:0)

假设你在MASM上,你可以使用运营商" DUP" 喜欢在

smallarray dword 10 DUP (?)

此行将定义一个数组,其中包含10个具有未知初始值的双字成员

要访问它的成员,您可以使用间接访问,例如

mov eax, [smallarray]    ;first member
mov eax, [smallarray+4]  ;second member
mov eax, [smallarray+8]  ;third member
mov eax, [smallarray+12] ;fourth member
mov eax, [smallarray+16] ;fifth member
;....... we used 4 bytes because the members are dword (4 bytes long)