title  Conditional operators and logical operations

dosseg

.model 	small			;Identifies type of memory model to use

.stack 	100h			; Identifies size of stack segment

.data				;Contains all variables for the program

num1   db 00000011b 
num2   db 00001010b
num3   db 11110000b
array   dw 10h, 20h, 30h, 40h, 50h, 60h, 70h, 80h

number1 dw 10h
number2 dw 20h
number3 dw 30h

.code				;Contains all code from program
main  	proc
      	mov   	ax,@data	;Required to setup the data segment in the ds register.
      	mov   	ds,ax


; implementing an if statement
;
;   if (ax < bx) {
;      cx = cx + 2;
;   } else {
;      cx = cx - 2;
;   }
;
        mov     cx, 5
        mov     ax, [number1]
        mov     bx, [number2]
        cmp     ax, bx  ; same as sub but it does not overwrite ax
        jge     else1     
        inc     cx
        inc     cx
        jmp     endif1
else1:  dec     cx
        dec     cx
endif1: nop

; implementing a for loop
;
;   for(ax = 1; ax != 8; ax++) {
;        cx = cx + 2;
;   }
;
        mov     ax, 1
for1:   cmp     ax, 8  ; same as sub but it does not overwrite ax
        je    forend1
        ; body of the loop
        inc     cx
        inc     cx
        ; end of body of the loop
        inc     ax
        jmp     for1
forend1: nop
        
;  implementing a while loop
;
;  ax = 10
;  while(ax > 0) {
;      ax = ax - 3  
;  }
        
        mov     ax, 10
while1: cmp     ax, 0
        jle     whileend1
        ; body of while loop
        sub     ax, 3
        ; end of body of while loop
        jmp     while1
whileend1: nop

; implementing a do...while loop
;
; ax = 3
; do {
;    ax = ax + 4
; while( ax < 20 )
;
        mov     ax, 3
do1:    ; beginning of the do-while loop
        add     ax, 4
        ; end of body of the do-while loop
        cmp     ax, 20
        jle     do1

        
; terminate
  	mov   	ax,4C00h	;Required to terminate program normally
	int   	21h
main  	endp
end   	main


