PhotoShaman

ASM.Лаба8

Apr 7th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; multi-segment executable file template.
  2.  
  3. data segment
  4.     ; add your data here!
  5.     pkey db 10, 13, "press any key...$"
  6.     PosArrayMax db "Max element in positive array: $"
  7.     PosArray db 10, 4, 6, 7, 13, 2, 1, 9, 0, 4, 3
  8.     PosArrayLen dw $-PosArray  
  9.     ArrayBiggerThen5 db 10, 13, "Bigger then 5: $"
  10.     ArrayZeroIndex db 10, 13, "Zero index: $"
  11.     Array db 4, -6, 1, -7, 6, 9, -1, 2, 9, 0, -8, 0
  12.     ArrayLen dw $-Array
  13.     ZeroIndex dw -1
  14. ends
  15.  
  16. stack segment
  17.     dw   128  dup(0)
  18. ends
  19.  
  20. code segment
  21. start:
  22. ; set segment registers:
  23.     mov ax, data
  24.     mov ds, ax
  25.     mov es, ax
  26.  
  27.     ; add your code here
  28.    
  29.     ;---Max element in positive array
  30.     mov cx, PosArrayLen  
  31.     lea si, PosArray
  32.     mov bx, 0                                      
  33.     cklPosArray:                    
  34.     cmp bl, [si]                    
  35.     ja nextIter
  36.     mov bl, [si]    
  37.     nextIter:
  38.     inc si                              
  39.     loop cklPosArray
  40.    
  41.     ;Output Max element in positive array    
  42.     lea dx, PosArrayMax
  43.     mov ah, 9h
  44.     int 21h
  45.     mov ax, bx
  46.     call OutInt
  47.    
  48.     ;---Count numbers > 5 & zero index                  
  49.     mov cx, ArrayLen
  50.     mov si, 0  ;array index
  51.     mov bx, 0  ;count numbers > 5
  52.     cklArray:
  53.     cmp Array[si], 5
  54.     jng toNextCmp
  55.     inc bx
  56.     toNextCmp:
  57.     cmp ZeroIndex, -1
  58.     jne toEndIter
  59.     cmp Array[si], 0
  60.     jne toEndIter
  61.     mov ZeroIndex, si
  62.     inc ZeroIndex
  63.     toEndIter:
  64.     inc si
  65.     loop cklArray
  66.    
  67.     ;Output Count numbers
  68.     lea dx, ArrayBiggerThen5
  69.     mov ah, 9
  70.     int 21h
  71.     mov ax, bx
  72.     call OutInt
  73.    
  74.     ;Output Zero index
  75.     lea dx, ArrayZeroIndex
  76.     mov ah, 9
  77.     int 21h  
  78.     mov ax, ZeroIndex
  79.     call OutInt
  80.     ;End                      
  81.     lea dx, pkey
  82.     mov ah, 9
  83.     int 21h        ; output string at ds:dx
  84.    
  85.     ; wait for any key....    
  86.     mov ah, 1
  87.     int 21h
  88.    
  89.     mov ax, 4c00h ; exit to operating system.
  90.     int 21h
  91.    
  92.     ;Output Int(0 - 99)
  93.     OutInt proc
  94.         aam
  95.         add ax,3030h
  96.         mov dl,ah
  97.         mov dh,al
  98.         mov ah,02
  99.         cmp dl,48   ;is the number starts as 0
  100.         je next
  101.         int 21h
  102.         next:
  103.         mov dl,dh
  104.         int 21h
  105.         ret
  106.     OutInt endp
  107. ends
  108.  
  109. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment