I am trying to print out the offset values.
(Is the term “print” correct? Is there another term for it?
Is the code correct? I am rather confused with documentation for assembly.
print_offsets: mov SI,0
mov CX,30
mov AH,2
int 21h
jmp offsloop
offsloop: cmp 0,Array[SI]
ja print_offset ;if the array element is nonzero
inc SI
dec CX
jnz offsloop
print_offset: mov DL,SI
mov AH,2
int 21h
If you’re trying to print numbers, your code is incorrect.
INT 21h, AH=2outputs an ASCII character. What your code is doing is putting the offset value into DL. DOS will treat that offset value as an ASCII character and output that instead.For example, suppose the first non-zero element is at an offset of 7. Your code will call
INT 21h, AH=2withDL=07. DOS will output the ASCII character 07h which is BEL (basically a system beep). Instead, you would probably wantDL=37hin order to output the ASCII character 37h which represents the number 7 digit.There are a couple of ways of solving this.
The first way is easy – if your Array never has more than 10 elements, you can simply add 30h to the offset to convert the offset value to the correct ASCII character value:
The second way is more complex because you need to implement a full integer-to-ascii conversion routine. But there are plenty of code samples out there that can do that.