I put "code tags" around your code for ya. Just the word "code" in square brackets at the beginning and "/code" in square brackets at the end. Makes it easier to cut-and-paste, and may improve the formatting. Not a big deal, but we like "code tags" around here.
You start off well...
org 100h
section .text
start:
mov bx, message ; get address of first char in message
firstloop:
mov dl, [bx] ; get char at address in BX
inc bx ; point BX to next char in message
cmp dl, 0 ; Is DL = null (that is, 0)?
je secondprep ; If yes, then quit
mov ah, 06 ; If no, then call int 21h service 06h
int 21h ; to print the character
jmp firstloop
secondprep:
mov bx, input ; get address of first char of input
secondloop: ; storing the value in input
mov ah , 00h ; service 00h (get keystroke)
int 16h ; call interrupt 16h (ah=00h
cmp al , 0dh ; is AL = 0DH?
je 20h
... but at this point, you lose me. This is going to jump into the middle of your PSP (Program Segment Prefix - the first 100h bytes of your .com file). This is probably where the "illegal instruction" comes from. At this point, the user is done. We want to check that the user has entered exactly ten digits (you do this later), and we want to zero-terminate the string (which you don't seem to do). If not 0Dh...
mov [bx], al ;if no, then store the character
mov dl, al
mov ah, 06h
int 21h
inc bx ; increment bx
jmp secondloop ;repeat for the next character
You might want to check bx right after the "inc", to make sure it doesn't get too big. It is a grave mistake to let user input overflow the buffer - that's what's wrong with "gets()". Don't do it!
Keep in mind that we start counting at zero. The "first" character is at [input + 0], the "tenth" character is at [input + 9]. When bx gets to 10, the pesky user has hit "enter" or has screwed up. You might even want to prompt "that's enough, thank you" before he hits "enter".
In any case, we want to zero-terminate the string at [input + 10].
thirdloop:
cmp al, 0Dh ; Is AL = 0Dh? (ASCII 13 = Return)
je quit ; If yes, then quit
thirdprep:
mov ax, bx ; moving ten digit input in BX into AX
mov bl, 1 ; BL= counter
I don't know what you propose to count here, but bl (and bh) are part of bx, so it gets clobbered.
mov bx, binary ; get first adress of binary
fourthloop:
cmp bx,11
je prompt ;compare bx to 11characters
mov bx, message2 ; if not equal to 11 characters, then display message2
jmp continue
prompt:
mov bx, message2
continue:
quit:
int 20h ; terminate program
section .data
message db "Enter a 10-digit binary number:", 10, 13, 0
message2 db "Please enter EXACTLY 10-digit binary number", 10, 13, 0
input TIMES 11 db 0,0,0,0,0,0,0,0,0,0,0
This is defining eleven copies of eleven zeros. More than you need, but it won't hurt.
base32 db 0,0,0,0
decimal db 0,0,0,0,0,0
binary db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
You're going to want to verify that a character is either a '0' or a '1' in your "convert string of binary to number" routine anyway, but you might want to do it before even putting it in the buffer - prompt with a definition of "binary number" if the user screws up.
Once you've got the string, "efficiently" convert to a number. The principles of converting a string to a number are similar...
; set a "result so far" to zero
top:
; get a character from the string
; make sure it's a valid character for our base
; if not bail out - zero is expected, else spank user?
; convert the character to a number
; for decimal digits - including binary - subtract '0' (the character '0', not the number 0!)
; hex or "duotrigesimal" characters are more complicated
; multiply the result-so-far by the base
; for binary, or other power of two, "shl"?
; add the number we got to result-so-far
; until done
Then store the result in a variable - you don't seem to have one yet - "number dw 0" (or "number resw 1" in "section .bss").
Converting a number to a string representing that number in different bases...
; divide the number by the base
; convert the remainder to a character
; here's how I'd do hex
add dl, '0'
cmp dl, '9'
jle skip
add dl, 7 ; or 27 if you like lowercase
skip:
; store the character in the string
; we're getting characters from right to left - store 'em that way!
; if quotient is zero, we're done
; if not, do it again
Examples for decimal and hex shouldn't be too hard to find. Duotrigesimal, not so much. I suspect that was the idea. But a hex routine ought to work, with minimal modification. Give it a shot!
Best,
Frank