Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #make_bin#
- ; BIN is plain binary format similar to .com format, but not limited to 1 segment;
- ; All values between # are directives, these values are saved into a separate .binf file.
- ; Before loading .bin file emulator reads .binf file with the same file name.
- ; All directives are optional, if you don't need them, delete them.
- ; set loading address, .bin file will be loaded to this address:
- #LOAD_SEGMENT=0100h#
- #LOAD_OFFSET=0000h#
- ; set entry point:
- #CS=0100h# ; same as loading segment
- #IP=0000h# ; same as loading offset
- ; set segment registers
- #DS=0100h# ; same as loading segment
- #ES=0100h# ; same as loading segment
- ; set stack
- #SS=0100h# ; same as loading segment
- #SP=FFFEh# ; set to top of loading segment
- ; set general registers (optional)
- #AX=0000h#
- #BX=0000h#
- #CX=0000h#
- #DX=0000h#
- #SI=0000h#
- #DI=0000h#
- #BP=0000h#
- ; add your code here
- MOV al,0 ;choose 1 or 0
- MOV dl,al
- MOV bx,9
- MOV cx,10
- CMP dl,0
- JE set_mem_asc
- CMP dl,1
- JE set_mem_desc
- JMP ending
- set_mem_asc:
- MOV ax,1400h
- MOV ds,ax
- MOV ax,0000h
- MOV si,ax
- JMP inner1
- set_mem_desc:
- MOV ax,0500h
- MOV ds,ax
- MOV ax,0010h
- MOV si,ax
- JMP inner2
- a_or_d:
- CMP dl,0
- JE inner1
- JMP inner2
- inner1: ;ascending
- DEC bx ; decrement counter
- MOV al,[si] ; move from table to register
- MOV ah,[si+1]
- CMP al,ah ; compare 2 numbers in vec2
- JA exchange ; if next number bigger, exchange numbers (we want bigger first)
- JMP check_and_inc
- inner2: ;descending
- DEC bx ; decrement counter
- MOV al,[si] ; move from table to register
- MOV ah,[si+1]
- CMP al,ah ; compare 2 numbers in memory
- JB exchange
- check_and_inc:
- INC si
- CMP bx,0 ; increment counters then check if we reached end of table
- JG a_or_d
- JMP reset_loop
- exchange:
- MOV [si],ah ;exchange numbers
- MOV [si+1],al
- MOV al,[si]
- MOV ah,[si+1]
- JMP check_and_inc
- reset_loop:
- DEC cx
- CMP cx,0
- JE ending
- MOV bx,9
- CMP dl,0
- JE set_mem_asc
- JMP set_mem_desc
- hlt
- ending:
- hlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement