PhotoShaman

АСМ.Зашквар

Mar 21st, 2017
91
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.     text db "Y = $"
  6.     pkey db 10,13, "press any key...$"
  7.     a db 2
  8.     b db 6
  9.     c db 19
  10.     x db 1
  11.     o dw 0
  12.     y 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 text
  28.     mov ah, 9
  29.     int 21h
  30.  
  31.     ;loop start
  32.     mov cx, 10  
  33.     mov bl, c
  34.     sub b, bl       ; b -= c
  35.     for_loop:
  36.         cmp x, 6
  37.         jnb xB6
  38.         ;x < 6
  39.         mov ax, 0
  40.         mov dx, 0
  41.         mov al, b
  42.         mov bx, 0
  43.         mov bl, x    ; ax = b - c    
  44.         idiv bx      ; ax = (b - c) / x
  45.        
  46.         mov bx, ax    
  47.         mov ax, 0
  48.         mov al, x    ; ax = x
  49.         mul x        ; x * x
  50.         add ax, bx   ; x * x + (b - c) / x  
  51.         jmp end_iterate
  52.         xB6:
  53.         ;x >= 6
  54.         mov al, a    ; ax = a
  55.         imul x       ; ax *= x
  56.         idiv b       ; ax /= b - c
  57.        
  58.         end_iterate:
  59.         inc x
  60.         ;mov ax, o
  61.         add y, ax   ; y += o  
  62.     loop for_loop
  63.     ;loop end
  64.    
  65.     mov ax, y
  66.     OutInt proc     ;output number 0 - 99
  67.         aam
  68.         add ax,3030h
  69.         mov dl,ah
  70.         mov dh,al
  71.         mov ah,02
  72.         cmp dl,48   ;is the number starts as 0
  73.         je next
  74.         int 21h
  75.         next:
  76.         mov dl,dh
  77.         int 21h
  78.     OutInt endp
  79.              
  80.     lea dx, pkey
  81.     mov ah, 9
  82.     int 21h         ; output string at ds:dx
  83.    
  84.     ; wait for any key....    
  85.     mov ah, 1
  86.     int 21h
  87.    
  88.     mov ax, 4c00h   ; exit to operating system.
  89.     int 21h    
  90. ends
  91.  
  92. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment