Reputation: 183
I'm using emu8086. I've a question which tasked me to display what we see on seven segment displays after converting from its hexa inputs. I should input my data in hexa, if it matches the hexa input of the seven segment table, it displays the decimal number, eg. 3FH = 0, 06H = 1. I'm using array to implement this program. Below is the working source program:
ORG 100H
MOV AL,[1840H] ;input in this memory location
MOV CL,0AH ; initialize length counter
AGAIN: CMP AL,MSG+BX ; compare to check if the data matches
JE RESULT ; jump to RESULT if data matched
INC BX ; increase decimal output by 1 if data not matched
LOOP AGAIN
MOV [1841H],0FFH ; display FF if no data matched the array
HLT
MSG DB 3FH, 06H, 5BH, 4FH,66H, 6DH,7DH,07H,7FH,6FH ; my array with hexa inputs
RESULT: MOV [1841H],BL ; display data if matched
I had this program working. But I've tried something which I switch my array MSG DB 3FH...
to a position after ORG 100H
and before MOV AL,[1840H]
, running the program will give an error message
"Unknown opcode skipped: 66, not 8086 instruction - not supported yet".
I can't find the reason why.
Anyone would have any idea what's the reason and can I fix anything to make my program work if I were to keep the array between ORG 100H
and MOV AL,[1840H]
?
Upvotes: 2
Views: 8814
Reputation: 39166
By moving the data array MSG in front of the first instruction you effectively asked emu8086 to execute it! The first bytes of MSG correspond to valid 8086 instructions (AAS
, PUSH ES
, POP BX
, and DEC DI
) but the fifth byte represents the operand size prefix which is not available in the 8086 processor!
To quickly solve your problem just jump over MSG:
ORG 100H
jmp start
MSG DB 3FH, 06H, 5BH, 4FH,66H, 6DH,7DH,07H,7FH,6FH
start:
But it's even better to just put it after your code like you had originally, so it's not in the way in the first place. There's no benefit to having the first instruction of your program be a jmp
when you could just have put the code there, unless you want it at a standard place in the binary so other things can edit the file. (.com
executables don't have metadata to tell the program-loader where the entry-point is; it's fixed at IP=100h, the first byte of the file.)
LOOP AGAIN
, the LOOP
instruction depends on the whole CX
register, yet you only initialized its low 8 bits via MOV CL,0AH
.BX
register to index the array, but you've never zeroed BX
so you can't be sure the program will operate fine.MOV [1841H],0FFH
, you seem to rely on emu8086 defaulting to the byte size when writing this immediate to a memory location. I would advice to always impose the size that you need, like in mov byte ptr [1841h], 255
.CMP AL,MSG+BX
.cmp al, [MSG+BX]
similar to your use of square brackets in mov AL, [1840H]
, MOV [1841H],0FFH
, and MOV [1841H],BL
?
For even more confusion (and some clarification) about the use of square brackets in MASM (emu8086 is MASM-style), read this Ross Ridge answer.My version of the revised program:
ORG 256
jmp start
msg db 3Fh, 06h, 5Bh, 4Fh, 66h, 6Dh, 7Dh, 07h, 7Fh, 6Fh
start:
mov al, [1840h]
xor bx, bx ; ArrayIndex (offset)
again:
cmp al, [msg+bx]
je result
inc bx
cmp bx, 10 ; NumberOfElements
jb again
mov bl, -1
result:
mov [1841h], bl ; display ARRAYINDEX if matched else display FF
hlt
Related / duplicates:
Upvotes: 6