storm@cs.mcgill.ca (Marc WANDSCHNEIDER) (06/21/91)
Given the following code: DATA_SEG SEGMENT PUBLIC PUBLIC SECTOR SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 DATA_SEG ENDS Why is the following instruction illegal.... (assuming BX has the value 4) MOV DX, SECTOR[BX] The book I am reading claims that this is because SECTOR is a byte label... I learned to program Assembler on the PDP11 where I could do the following: SECTOR: .byte 10, 11, 12, 13, 14, 15, 16, 17, 18 ..etc MOV #SECTOR, r1 MOVB (r1)+, r2 or MOV (R1)+, r2 Can somebody give me an explanation..? [If possible, please forward all replies to storm@sizone.UUCP please. Thanks] ./*- storm@bart.cs.mcgill.ca storm@sizone.UUCP -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storm@cs.mcgill.ca McGill University It's 11pm, do YOU Marc Wandschneider Montreal, CANADA know what time it is? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a_rubin@dsg4.dse.beckman.com (Arthur Rubin) (06/21/91)
In <1991Jun21.031758.11264@cs.mcgill.ca> storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: >Given the following code: >DATA_SEG SEGMENT PUBLIC > PUBLIC SECTOR >SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 >DATA_SEG ENDS >Why is the following instruction illegal.... (assuming BX has the value 4) >MOV DX, SECTOR[BX] You need : MOV DX, WORD PTR SECTOR[BX] ; the assembler knows that SECTOR is a byte address. -- 2165888@mcimail.com 70707.453@compuserve.com arthur@pnet01.cts.com (personal) a_rubin@dsg4.dse.beckman.com (work) My opinions are my own, and do not represent those of my employer.
andy@bluemoon.uucp (Andy Vaught) (06/22/91)
storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: > > Given the following code: > > DATA_SEG SEGMENT PUBLIC > PUBLIC SECTOR > SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 > DATA_SEG ENDS > > Why is the following instruction illegal.... (assuming BX has the value 4) > > MOV DX, SECTOR[BX] > The above is perfectly legal. The problem is convincing MASM of its legality. You might need an "OFFSET" keyword before "SECTOR". I don't know, I use Turbo Assembler, which has much more rational syntax. ------------------------------------------------------------------ Andy Vaught (Fuzzy Andy) :: C Code. C Code Run. Run C code, Run... Grad Student on Vacation :: before I whip out my 12-Gauge andy@bluemoon.uucp :: Dynamic Debugging Tool!
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (06/23/91)
In article <ysyw42w164w@bluemoon.uucp> andy@bluemoon.uucp (Andy Vaught) writes: >storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: >> SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ... >> MOV DX, SECTOR[BX] >> >The above is perfectly legal. The problem is convincing MASM of its >legality. You might need an "OFFSET" keyword before "SECTOR". I don't >know, I use Turbo Assembler, which has much more rational syntax. What does it do? The instruction looks ambiguous to me, since DX is word sized and SECTOR[BX] is byte sized. Does TASM move a word (i.e 0B0A if BX=0)? That's probably not what was intended... Duncan Murdoch dmurdoch@watstat.waterloo.edu
andy@bluemoon.uucp (Andy Vaught) (06/23/91)
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes: > In article <ysyw42w164w@bluemoon.uucp> andy@bluemoon.uucp (Andy Vaught) write > >storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: > >> SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 > ... > >> MOV DX, SECTOR[BX] > What does it do? The instruction looks ambiguous to me, since DX is word > sized and SECTOR[BX] is byte sized. Does TASM move a word (i.e 0B0A if > BX=0)? That's probably not what was intended... > > Duncan Murdoch > dmurdoch@watstat.waterloo.edu Since the author specified the DX register, the assembler should, IMHO, generate a word move without complaint. "SECTOR" is only an offset into a memory location. Although "bytes" were specified, this is an artifact of the assembler and its rigid (rabid?) typechecking. The whole thing is a matter of taste- I feel that assembler (like C) should let you do weird things without complaint. ------------------------------------------------------------------ Andy Vaught (Fuzzy Andy) :: C Code. C Code Run. Run C code, Run... Grad Student on Vacation :: before I whip out my 12-Gauge andy@bluemoon.uucp :: Dynamic Debugging Tool!
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (06/24/91)
In article <k88Z44w164w@bluemoon.uucp> andy@bluemoon.uucp (Andy Vaught) writes: >dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes: > >> In article <ysyw42w164w@bluemoon.uucp> andy@bluemoon.uucp (Andy Vaught) write >> >storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: >> >> SECTOR DB 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 >> ... >> >> MOV DX, SECTOR[BX] >> What does it do? The instruction looks ambiguous to me, since DX is word >> sized and SECTOR[BX] is byte sized. Does TASM move a word (i.e 0B0A if >> BX=0)? That's probably not what was intended... > >Since the author specified the DX register, the assembler should, IMHO, >generate a word move without complaint. "SECTOR" is only an offset into a >memory location. Although "bytes" were specified, this is an artifact of >the assembler and its rigid (rabid?) typechecking. If we didn't want to type SECTOR as a byte, we could have put a colon after it, and it would be an offset into a memory location. >The whole thing is a >matter of taste- I feel that assembler (like C) should let you do weird >things without complaint. I agree that it's a matter of taste, but I still think that the original instruction was ambiguous. You seem to be saying the data size in instructions like MOV dest,source should be the same as the size of the register involved. This doesn't help with a case like MOV DX,AL (which I hope you'll agree shouldn't assemble). I guess we're lucky that Intel never lets you make two memory references in the same instruction, or we'd have another special case to work out. It seems to give a cleaner language definition to say that the source and destination must be the same size, and then allow typecasts like MOV DX, WORD PTR SECTOR[BX] for the cases where you want to do weird things. Duncan Murdoch dmurdoch@watstat.waterloo.edu P.S. I bet the original poster, whose name I've lost, really did intend to get 000A in DX in the example above!
rcollins@gumby.Altos.COM (Robert Collins) (06/25/91)
In article <ysyw42w164w@bluemoon.uucp> andy@bluemoon.uucp (Andy Vaught) writes: >The above is perfectly legal. The problem is convincing MASM of its >legality. You might need an "OFFSET" keyword before "SECTOR". I don't >know, I use Turbo Assembler, which has much more rational syntax. > And TASM has an impossible "bug-set" when dealing with 32-bit (USE32) programming. Sorry, even though MASM has its limitations, unfortunately TASM has even more...which make it unusable in my line of work.