Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #make_bin#
  2.  
  3. ; BIN is plain binary format similar to .com format, but not limited to 1 segment;
  4. ; All values between # are directives, these values are saved into a separate .binf file.
  5. ; Before loading .bin file emulator reads .binf file with the same file name.
  6.  
  7. ; All directives are optional, if you don't need them, delete them.
  8.  
  9. ; set loading address, .bin file will be loaded to this address:
  10. #LOAD_SEGMENT=0100h#
  11. #LOAD_OFFSET=0000h#
  12.  
  13. ; set entry point:
  14. #CS=0100h# ; same as loading segment
  15. #IP=0000h# ; same as loading offset
  16.  
  17. ; set segment registers
  18. #DS=0100h# ; same as loading segment
  19. #ES=0100h# ; same as loading segment
  20.  
  21. ; set stack
  22. #SS=0100h# ; same as loading segment
  23. #SP=FFFEh# ; set to top of loading segment
  24.  
  25. ; set general registers (optional)
  26. #AX=0000h#
  27. #BX=0000h#
  28. #CX=0000h#
  29. #DX=0000h#
  30. #SI=0000h#
  31. #DI=0000h#
  32. #BP=0000h#
  33.  
  34. ; add your code here
  35.  
  36. MOV al,0 ;choose 1 or 0
  37. MOV dl,al
  38.  
  39. MOV bx,9
  40. MOV cx,10
  41.  
  42. CMP dl,0
  43. JE set_mem_asc
  44. CMP dl,1
  45. JE set_mem_desc
  46. JMP ending
  47.  
  48. set_mem_asc:
  49. MOV ax,1400h
  50. MOV ds,ax
  51. MOV ax,0000h
  52. MOV si,ax
  53. JMP inner1
  54.  
  55. set_mem_desc:
  56. MOV ax,0500h
  57. MOV ds,ax
  58. MOV ax,0010h
  59. MOV si,ax
  60. JMP inner2
  61.  
  62. a_or_d:
  63. CMP dl,0
  64. JE inner1
  65. JMP inner2
  66.  
  67. inner1: ;ascending
  68. DEC bx ; decrement counter
  69. MOV al,[si] ; move from table to register
  70. MOV ah,[si+1]
  71. CMP al,ah ; compare 2 numbers in vec2
  72. JA exchange ; if next number bigger, exchange numbers (we want bigger first)
  73. JMP check_and_inc
  74.  
  75. inner2: ;descending
  76. DEC bx ; decrement counter
  77. MOV al,[si] ; move from table to register
  78. MOV ah,[si+1]
  79. CMP al,ah ; compare 2 numbers in memory
  80. JB exchange
  81.  
  82. check_and_inc:
  83. INC si
  84. CMP bx,0 ; increment counters then check if we reached end of table
  85. JG a_or_d
  86. JMP reset_loop
  87.  
  88. exchange:
  89. MOV [si],ah ;exchange numbers
  90. MOV [si+1],al
  91. MOV al,[si]
  92. MOV ah,[si+1]
  93. JMP check_and_inc
  94.  
  95. reset_loop:
  96. DEC cx
  97. CMP cx,0
  98. JE ending
  99. MOV bx,9
  100. CMP dl,0
  101. JE set_mem_asc
  102. JMP set_mem_desc
  103.  
  104.  
  105.  
  106.  
  107. hlt
  108. ending:
  109. hlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement