PhotoShaman

ASM.Лаба5

Mar 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----------------------Задание 1
  2. ; multi-segment executable file template.
  3.  
  4. data segment
  5.     ; add your data here!  
  6.     bordersText db "Input a & b: $"
  7.     inputNumbersText db 10,13, "Input numbers: $"
  8.     countGoodNumbers db 10,13, "Count good numbers: $"  
  9.     pkey db 10,13, "press any key...$"
  10.     a db ?
  11.     b db ?
  12.     count dw 0
  13. ends
  14.  
  15. stack segment
  16.     dw   128  dup(0)
  17. ends
  18.  
  19. code segment
  20. start:
  21. ; set segment registers:
  22.     mov ax, data
  23.     mov ds, ax
  24.     mov es, ax
  25.  
  26.     ;add your code here
  27.     mov dx, offset bordersText
  28.     mov ah, 9
  29.     int 21h
  30.    
  31.     mov ah, 1
  32.     int 21h      
  33.     mov a, al
  34.    
  35.     mov ah, 1
  36.     int 21h      
  37.     mov b, al
  38.    
  39.     mov dx, offset inputNumbersText
  40.     mov ah, 9
  41.     int 21h
  42.    
  43.     ;loop start
  44.     mov cx, 10
  45.     for_loop:
  46.    
  47.         ;input number
  48.         mov ah, 1
  49.         int 21h      
  50.        
  51.         cmp al, a
  52.         jb end_iterate
  53.        
  54.         cmp al, b
  55.         ja end_iterate
  56.            
  57.         inc count  
  58.         end_iterate:  
  59.     loop for_loop
  60.     ;loop end
  61.      
  62.     lea dx, countGoodNumbers
  63.     mov ah, 9
  64.     int 21h  
  65.    
  66.     mov ax, count
  67.     OutInt proc ; output number 0 - 99
  68.         aam
  69.         add ax,3030h
  70.         mov dl,ah
  71.         mov dh,al
  72.         mov ah,02
  73.         cmp dl, 48 ; is the number starts as 0
  74.         je next
  75.         int 21h
  76.         next:
  77.         mov dl,dh
  78.         int 21h
  79.     OutInt endp
  80.              
  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. ends
  92.  
  93. end start ; set entry point and stop the assembler.
  94.  
  95. //-----------------------Задание 2
  96.  
  97. ; multi-segment executable file template.
  98.  
  99. data segment
  100.     ; add your data here!
  101.     pkey db 10,13,"press any key...$"
  102.     a dw 2
  103.     b dw 6
  104.     c dw 19
  105.     y dw 0
  106. ends
  107.  
  108. stack segment
  109.     dw   128  dup(0)
  110. ends
  111.  
  112. code segment
  113. start:
  114. ; set segment registers:
  115.     mov ax, data
  116.     mov ds, ax
  117.     mov es, ax
  118.  
  119.     ; add your code here
  120.    
  121.     mov dx, c
  122.     sub b, dx  ; b = b - c
  123.    
  124.     ;loop start
  125.     mov cx, 10  ; x = 10
  126.     for_loop:
  127.     cmp cx, 6
  128.     jnb xB6
  129.     ;x < 6:
  130.     ;ax = (b - c) / x
  131.     mov ax, b
  132.     mov bx, cx  
  133.     idiv cl
  134.     mov bx, ax
  135.     ;ax = x * x
  136.     mov ax, cx
  137.     mul ax
  138.     ;ax = (x * x) + ((b - c) / x)
  139.     add ax, bx
  140.    
  141.     jmp end_iterate
  142.     xB6:
  143.     ;x >= 6:
  144.     ;ax = x * a
  145.     mov ax, a
  146.     mul cl
  147.     ;ax = (x * a) / (b - c)
  148.     mov bx, b
  149.     idiv bl                
  150.  
  151.     end_iterate:
  152.     add y, ax
  153.     loop for_loop
  154.     ;loop end
  155.    
  156.     mov ax, y
  157.     OutInt proc     ;output number 0 - 99
  158.         aam
  159.         add ax,3030h
  160.         mov dl,ah
  161.         mov dh,al
  162.         mov ah,02
  163.         cmp dl,48   ;is the number starts as 0
  164.         je next
  165.         int 21h
  166.         next:
  167.         mov dl,dh
  168.         int 21h
  169.     OutInt endp
  170.              
  171.     lea dx, pkey
  172.     mov ah, 9
  173.     int 21h        ; output string at ds:dx
  174.    
  175.     ; wait for any key....    
  176.     mov ah, 1
  177.     int 21h
  178.    
  179.     mov ax, 4c00h ; exit to operating system.
  180.     int 21h    
  181. ends
  182.  
  183. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment