Advertisement
Guest User

PU1

a guest
Mar 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data segment
  2. n1        dw ?
  3. n2        dw ?
  4. n3        dw ?
  5. array1 dw 100 dup(0)
  6. array2 dw 100 dup(0)
  7. array3 dw 100 dup(0)
  8. sumRow dw ?
  9. sumCol dw ?
  10. finalSum dw ?
  11. minSize dw ?
  12. newline        db 13,10,'$'
  13. answer db 7 dup(?),'$'
  14. buffer db 06,00,5 dup(?)
  15. msgEnterN     db 'Input size of matrix: $'
  16. msgEl       db 13,10,'Input elements: ',13,10,'$'
  17. msgSumRow  db 'Sum of 1st row: $'
  18. msgSumCol  db 'Sum of last col: $'
  19. msgFinalSum  db 'Final sum: $'
  20. msgLowestSize  db 'Lowest size: $'
  21. msgRes  db 'Result: $'
  22. data ends
  23.  
  24. code segment
  25. assume cs:code,ds:data
  26.  
  27. ; ????????? ?????????????? ????????? ????? ? ?????? ????????
  28. ; B??? - AX - ?????
  29. ; B???? - ?????? ?? ?????? DS:BX
  30. bin2str   proc
  31.             push   dx
  32.             push   cx
  33.             push   bx
  34.             push   si
  35.             push   ax
  36.             mov    cx,6
  37. fill_buff:  mov    byte ptr[bx+1],'' ; ????????? ?????? ?????????
  38.             inc    bx
  39.             loop   fill_buff
  40.             mov    si,10        ; |SI|:=10
  41.             or     ax,ax        ; ? |AX| - ????????????? ?????
  42.             jns    clr_div      ; ???? +, ??????? ?? clr_div
  43.             neg    ax           ; ?????, ?????? ????
  44. clr_div:    sub    dx,dx        ; ???????? ??????? ???????? ????????
  45.             div    si           ; |DX:AX| / 10
  46.             add    dx,'0'       ; ????????????? ? ?????????? ???
  47.             dec    bx           ; |BX|--
  48.             mov    [bx+1],dl    ; ????????? ???????. ????? ? ??????
  49.             or     ax,ax        ; ? ???????? ax - 0?
  50.             jnz    clr_div      ; ???? ?? 0, ?????????
  51.             pop    ax           ;
  52.             or     ax,ax        ; ???????? ????? ???????????? ?
  53.             jns    no_more      ; ???? ???, ??????? ? no_more
  54.             dec    bx           ; |BX|--
  55.             mov    byte ptr[bx+1],'-'  ; ????????? ? ?????? ???? '-'
  56. no_more:    pop    si
  57.             pop    bx
  58.             mov    byte ptr[bx],6      ; ????????? ??????? ????????
  59.             pop    cx
  60.             pop    dx
  61.             ret
  62. bin2str     endp
  63. ; ????????? ?????????????? ?????? ???????? ? ???????? ?????
  64. ; B??? - DS:BX - ????? ??????
  65. ; B???? - AX - ????? ?? ??????
  66. str2bin   proc
  67.             push   bx
  68.             push   cx
  69.             sub    AX,AX
  70.             sub    ch,ch
  71.             mov    cl,byte ptr[bx]   ; ??????? ???????? - ? CX
  72. blanks:     cmp    byte ptr[bx+1],'' ; ???? ???????? ????????
  73.             jne    chk_neg
  74.             inc    bx
  75.             loop   blanks
  76.             jmp    good              ; ?? ?????????? ?????. ????????? - 0
  77. ; ????????? ??????? ??????????? ? ?????? ????? "-"
  78. chk_neg:    cmp    byte ptr[bx+1],'-'
  79.             jne    chk_pos
  80.             inc    bx                ; ?????????? ?????????
  81.             dec    cx                ; ????????? ???????
  82.             call   conv_ab           ; ??????? ????????? ??????????????
  83.             jc     thru
  84.             cmp    AX,32768          ; ????? < -32768
  85.             ja     no_good           ; ??, ??????
  86.             neg    AX                ; ???????? ???? ?????
  87.             js     good              ; OK, ???????
  88. ; ????????? ??????? ??????????? ? ??????, ???? ???? ?? ?????
  89. chk_pos:    cmp    byte ptr[bx+1],'+'; sign '+'?
  90.             jne    go_conv   ; ???, ???? ?? ??????????????
  91.             inc    bx        ; ???????? ????????? ? ??????
  92.             dec    cx        ; ????????? ??????? ????????
  93. go_conv:    call   conv_ab   ; ????????????? ?????? ? ?????
  94.             jc     thru      ; ? ?????? ?????? - ?? ?????
  95.             cmp    AX,32767  ; ????? ?? ??????? ???????
  96.             ja     no_good   ; ??????? ??????, ??????
  97. good:       clc              ; ???????? ???? CY
  98.             jnc    thru
  99. no_good:    stc              ; Set carry flag
  100. thru:       pop    cx        ; ???????????? ???????? ?????????
  101.             pop    bx
  102.             jmp    skipit
  103. ;
  104. ; ????????? ?????????? ?????????????? ?????
  105. conv_ab   proc
  106.             push   bp
  107.             push   bx
  108.             push   si
  109.             mov    bp,bx  ; ????????? ????????? ?? ?????? ? BX
  110.             xor    bx,bx  ; ???????? BX
  111. range:      cmp    byte ptr ds:[bp+1],'0' ; ?????? - ????? ?
  112.             jb     non_dig                ; ??? ?? ?????
  113.             cmp    byte ptr ds:[bp+1],'9' ; ?????? > '9'
  114.             jbe    digit                  ; ?????? - ?????
  115. non_dig:    stc                     ; ?????????? ???? ??????
  116.             jc     end_conv         ; ? ????? ?? ?????????
  117. digit:      mov    si,10
  118.             push   dx            ; ????????? DX
  119.             mul    si            ; |Ax| * |SI| -> |DX:AX|
  120.             pop    dx            ; ???????????? DX
  121.             mov    bl,ds:[bp+1]  ; ????? ????????? ?????? ?? ??????
  122.             and    bx,0fh        ; ????????????? ?????? ? ????????
  123.             add    AX,bx         ; ???????? ????? ? ??????? ??????????
  124.             jc     end_conv      ; ???? ????????? ??????? ?????, ?? ?????
  125.             inc    bp            ; ????? ???? ????? ? ??????
  126.             loop   range         ; ???????? ???? ?? ?????????? ????????
  127.             clc                  ; ???????? ???? ???????? (??? ??????)
  128. end_conv:   pop    si            ; ???????????? ???????? ? ?????
  129.             pop    bx
  130.             pop    bp
  131.             ret
  132. conv_ab     endp
  133. skipit:     ret
  134. str2bin     endp
  135.  
  136.  
  137.  
  138. ;????? ?? ????? ??????????? str - ??????
  139. write macro  str
  140.     push    ax
  141.     push    dx
  142.  
  143.     lea     dx,str
  144.     mov     ah,09h  
  145.     int     21h
  146.  
  147.     pop     dx
  148.     pop     ax
  149. endm
  150.  
  151. ;???? ????? ? ??????????
  152. ;?????: ????? ? ax
  153. InputDigit macro
  154. push bx
  155. push dx
  156. write newline
  157. lea dx,buffer
  158. mov ah,0ah
  159. int 21h
  160. mov bx,dx
  161. inc bx
  162. call str2bin; ? bx - ????? ??????, ax - ?????
  163. pop dx
  164. pop bx
  165. endm
  166.  
  167. ;????? ????? ? ?? ?? ?????
  168. OutputDigit macro
  169. push bx
  170. push dx
  171. lea bx,answer
  172. call bin2str ; ? ax ?????, ? bx - ????? ??????
  173. lea dx,[answer+1]
  174. mov ah,09h
  175. int 21h
  176. pop dx
  177. pop bx
  178. endm
  179.  
  180. ; ?????? ??????? ???????
  181. ; matrix - ????? ??????? n- ???????????
  182. InputMatrix macro matrix,n
  183.     Local i,j; i - ?? ???????? j -?? ???????
  184.     push bx
  185.     push ax
  186.     lea     bx,matrix
  187.     mov     cx,n
  188.     i:    
  189.     push    cx
  190.     mov     cx,n
  191.     mov     si,0
  192.     j:  
  193.  
  194.     InputDigit
  195.     mov     word ptr[bx][si],ax
  196.     add     si,2
  197.  
  198.    
  199.     loop    j
  200.  
  201.     add     bx,n
  202.     add     bx,n
  203.     pop     cx
  204.     loop    i
  205.     pop ax
  206.     pop bx
  207. endm
  208.  
  209. OutputMatrix macro matrix,n
  210.     local i,j
  211.    
  212.     lea     bx,matrix
  213.     mov     cx,n
  214.     i:  
  215.     push    cx
  216.     mov     cx,n
  217.     mov     si,0
  218.     write newline  
  219.     j:  
  220.     xor ax,ax
  221.     mov ax,word ptr[bx][si]
  222.     OutputDigit
  223.     add si,2
  224.     loop    j
  225.    
  226.     add     bx,n
  227.     add     bx,n
  228.    
  229.     pop     cx
  230.     loop    i
  231.    
  232. ENDM
  233. ; ?????? ?????????? ?????????????? ???????? ? ?????????
  234. ; matrix - ????? ??????? n- ?? ???????????
  235. FuncMatrix macro matrix,n
  236. local view1
  237. mov sumCol,0
  238. mov sumRow,0
  239. push bx
  240. lea bx,matrix
  241. mov cx,n
  242. mov si,0
  243. push si
  244. view1:
  245. mov si,n
  246. add si,n
  247. sub si,2
  248. mov ax,word ptr[bx][si]
  249. add sumCol,ax
  250. add bx,n
  251. add bx,n
  252. pop si
  253. push bx
  254. lea bx,matrix
  255. mov ax,word ptr[bx][si]
  256. add sumRow,ax
  257. add si,2
  258. pop bx
  259. push si
  260.  
  261. loop view1
  262. mov ax,sumCol
  263. write newline
  264. write msgSumCol
  265. OutputDigit
  266.  
  267. mov ax,sumRow
  268. write newline
  269. write msgSumRow
  270. OutputDigit
  271.  
  272. pop bx
  273. ENDM
  274.  
  275. ; ????????? ?????????? ??????????? ??????????? ??????
  276. ; ????? : minSize ???????? ??????????? ???????????
  277. MinSizeF proc
  278. mov ax,n1
  279. mov minSize,ax
  280. IRPC it,<23>
  281. local lower,higher
  282. mov ax,n&it
  283. cmp minSize,ax
  284. ja lower
  285. jb higher
  286. lower: mov minSize,ax
  287. higher:
  288. ENDM
  289. ret
  290. MinSizeF endp
  291.  
  292.  
  293. start:
  294.     mov     ax,data
  295.     mov     ds,ax
  296.     mov finalSum,0
  297. IRPC num,<123>
  298.    
  299.     write newline
  300.     write msgEnterN
  301.     InputDigit
  302.     mov n&num,ax
  303.    
  304.     write newline
  305.     write msgEl
  306.     InputMatrix array&num,n&num
  307.     OutputMatrix array&num,n&num
  308.     FuncMatrix array&num,n&num
  309.     mov ax,sumCol
  310.     add finalSum,ax
  311.     mov ax,sumRow
  312.     add finalSum,ax
  313. ENDM
  314. call MinSizeF
  315. write newline
  316. write msgLowestSize
  317. mov ax,minSize
  318. OutputDigit
  319. write newline
  320. write msgFinalSum
  321. mov ax,finalSum
  322. OutputDigit
  323.  
  324. write newline
  325. write newline
  326. write msgRes
  327. mov ax,finalSum
  328. mov bx,minSize
  329. mov dx,0
  330. div bx
  331. OutputDigit
  332.  
  333. mov     ax,4c00h
  334. int     21h
  335. code ends
  336. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement