1

I saw this code to generate and display a square wave on a CRO.

data segment

base_add equ 0ef40h
porta equ base_add+0 
portb equ base_add+1
portc equ base_add+2
control_word equ base_add+3

data ends

code segment
assume cs:code, ds:data
start : mov ax, data
mov ds, ax
mov dx, control_word
mov al, 80h
out dx, al


up2:
 mov cx, 000ffh
 mov al, 00h
 mov dx, portb

 mov al, 00h

  here1: out dx,
loop here1

mov cx, 00ffh

     mov al, 0ffh
here2: out dx, al
 loop here2

mov ah, 0bh   ; LINE1
int 21h

or al, al    ; LINE2
jz up2

mov ah, 4ch
int 21h
code ends
end start

Towards the end, what is the use of mov ah, 0Bh interrupt and or al, al?
Isn't or al, al basically just al? What is the need to explicitly mention it?
I even tried to find out what 0Bh interrupt does, but I could not make sense out of what I read. Any help on this would be appreciated. Thanks!

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
  • 2
    Use a DOS reference to see what each service does. `0bh` is "Check Standard Input Status". It returns `0` if there is no input available. Yes, the result of `or al,al` is just `al` but more importantly it sets the zero flag if `al` is zero and that's what it is used for in the code. It just waits for a keypress. – Jester Mar 27 '18 at 16:42
  • 2
    `or al,al` is there to set flags like a comparison of `al` against zero, [as an inefficient alternative to `test al,al`](https://stackoverflow.com/questions/33721204/test-whether-a-register-is-zero-with-cmp-reg-0-vs-or-reg-reg/33724806#33724806) (but had no perf downside on very old CPUs, like before Pentium II, when 16-bit code was common). – Peter Cordes Mar 27 '18 at 17:13

1 Answers1

2

That's MSDOS assembly code.

mov ah, 0Bh   ; LINE1
int 21h

Calls DOS to check whether a character is available on standard input. This call will return 0 if no char available, 0xFF when a character is available. The return value will be given back via the al register, so

or al, al    ; LINE2
jz up2

will test whether a character is available (or al, al will only be zero when al is zero to begin with), and jump to up2 if there's nothing to read.

Tip: if you're working with DOS, go grab a copy of Ralf Brown's Interrupt list

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
fvu
  • 32,488
  • 6
  • 61
  • 79