CS401 Assignment Solution 2018
#1
 
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
[img=648x439]file:///C:/Users/sam/AppData/Local/Temp/OICE_2C0630CB-512F-4478-9498-F9B951A3EB7D.0/msohtmlclip1/01/clip_image001.jpg[/img][img=644x420]file:///C:/Users/sam/AppData/Local/Temp/OICE_2C0630CB-512F-4478-9498-F9B951A3EB7D.0/msohtmlclip1/01/clip_image002.jpg[/img][img=654x418]file:///C:/Users/sam/AppData/Local/Temp/OICE_2C0630CB-512F-4478-9498-F9B951A3EB7D.0/msohtmlclip1/01/clip_image003.jpg[/img]
  


Possibly Related Threads…
Thread Author Replies Views Last Post
  CS401 GDB Solution Fall 2020 Ayra Suleman 1 1,749 08-06-2020, 12:12 PM
Last Post: imranlatif
  CS401 Assignment 1 Solution Spring 2020 Ayra Suleman 0 772 06-11-2020, 01:43 AM
Last Post: Ayra Suleman
  CS401 Assignment 3 Solution Fall 2020 Ayra Suleman 0 605 01-20-2020, 12:35 AM
Last Post: Ayra Suleman
  CS401 Assignment 2 Solution Fall 2019 Ayra Suleman 0 605 11-26-2019, 11:33 PM
Last Post: Ayra Suleman
  CS401 Assignment Solution Fall 2019 Ayra Suleman 0 415 11-15-2019, 02:44 AM
Last Post: Ayra Suleman
  CS401 GDB Solution Spring 2019 Ayra Suleman 0 2,236 08-10-2019, 01:13 AM
Last Post: Ayra Suleman
  CS401 Assignment Solution Spring 2019 Ayra Suleman 0 516 07-23-2019, 08:18 PM
Last Post: Ayra Suleman
  CS401 Assignment 3 Solution Pakistani 1 7,470 07-22-2019, 02:46 PM
Last Post: Hotlixious
  CS401 assignment 3 Muhammad Yaseen 0 431 07-22-2019, 11:30 AM
Last Post: Muhammad Yaseen
  CS401 Assignment 2 Solutinn Spring 2019 Mishi Khan 0 785 05-31-2019, 02:03 AM
Last Post: Mishi Khan



Users browsing this thread:
1 Guest(s)