CS401 Assignment Solution 2018

Cs401 assignment No 1
Solution :

 [org 0x100]
jmp start
data:    dw  8,2,0,0,-1,-1,-7,-7,-9                    
swap:   db 0                                                                
start:    mov bx,0                                                         ; initialize array index to zero
            mov byte [swap],0                                          ; rest swap flag to no swaps              
loop1:  mov ax, [data+bx]                                           ; load number in ax
            cmp ax, [data+bx+2]                                       ; compare with next number
            jae noswap                                                      ;no swap if already in order
            mov dx,[data+bx+2]                                        ; load second element in dx
            mov [data+bx+2], ax                                       ;store first number in second
            mov [data+bx], dx                                           ; store second number in first
            mov byte [swap], 1                                         ;flag that a swap has been done
noswap:           add bx,2                                              ; advance bx to next index
                        cmp bx, 11                                          ; are we at last index
                        jne loop1                                             ; if not compare next two
                        cmp byte [swap], 1                             ;check if a swap has been done
                        je start                                                 ; if yes make another pass
                        mov ax, 0x4c00                                               ;terminate program
                        int 0x21

Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by fubbave
10-09-2021, 11:34 PM
Last Post by fubbave
10-03-2021, 12:24 PM

Users browsing this thread: 1 Guest(s)