0

I'm working on an assembly practice problem and I need to draw y=2x^2 on the screen using INT 10h. I have completed my code but it's giving me an error when assembling: A2155 cannot use 16-bit register with a 32-bit address error on line 27 (it's marked with ** in the code below. This code also does not use int 10h. Do I have to call it or passing some data or registers to a register is enough? Sorry I'm very new to this concept and 2D graphics with Assembly.

My code is:

INCLUDE Irvine32.inc

.data
num dw 0

.code
main PROC
    mov ax, 0A000h ;Set the segment address of the video buffer
    mov es, ax ;to ES

L1:
    mov bx, num 
    mov ax, 2 ;Set AX to the coefficient of x^2
    mul bx ;Calculate 2x^2
    mov bx, ax ;Move the result to BX
    mov ax, 0C000h ;Set the segment address of the video buffer
    mov ds, ax ;to DS
    mov ax, 0 ;Set AX to the current y-value
    mov cx, bx ;Move the result of 2x^2 to CX
    mov al, 0111b ;Set AL to the color of the pixel
    mov di, cx ;Set DI to the current x-value
**  mov es:[di], ax ;Draw the pixel
    inc num ;Increment the x-value
    cmp num, 100 ;Compare the x-value to the ending x-value
    jl L1 ;If x is less than the ending x-value, loop

    ret ;Exit the program
main ENDP
END main
cptalpdeniz
  • 368
  • 1
  • 11
  • Does this answer your question? [\[MASM\]Another 'cannot use 16-bit register with a 32-bit address' error](https://stackoverflow.com/questions/27097644/masmanother-cannot-use-16-bit-register-with-a-32-bit-address-error) – DarkAtom Dec 08 '22 at 23:50
  • I tried that but it says multiple .MODEL directives found : .MODEL ignored – cptalpdeniz Dec 09 '22 at 00:00

1 Answers1

0

It looks like the Irvine32.inc is probably setting up flat model 32-bit addressing. Your code is written for MS-DOS, so you want something like small model 16-bit addressing. As a starting point, change the first line to:

.model small, c

It also looks like you're using MASM as your assembler. Recent versions of MASM produce COFF files by default, which is intended to target 32-bit (or 64-bit) Windows. To target MS-DOS, you'll want to need the /omf flag on the MASM command line. If you fail to do so, you'll get an error that may appear unrelated, about "undefined symbol DGROUP".

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • that seems to be the case and and I did try yours however this time I got `multiple .MODEL directives found : .MODEL ignored` and the original error. – cptalpdeniz Dec 09 '22 at 00:01
  • also how do I add the `/omf` flag when I'm running VS 2022? – cptalpdeniz Dec 09 '22 at 00:05
  • 1
    @cptalpdeniz: You don't want to add the `.model` line before/after the include. You want to delete the `.include` line and *replace* it with the `.model` directive. As far as adding the flag to be used inside of VS...I don't recall (and don't have a copy of VS 2022 installed to check with right now). – Jerry Coffin Dec 09 '22 at 00:44
  • 1
    @cptalpdeniz: Irvine32 isn't a DOS library at all, it's for native Windows programs with `.386` / `.model flat, stdcall`. (So yes, 32-bit flat memory model. IDK if it uses those directives itself in the `.inc`). https://asmirvine.com/gettingStartedVS2017/index.htm / [What is the Irvine32 library and why do we use it?](https://stackoverflow.com/q/54386649) . It has console text input/output functions (with a custom calling convention where everything is call-preserved), also a messagebox https://csc.csudh.edu/mmccullough/asm/help/source/irvinelib/msgboxask.htm . For DOS, you'd want Irvine16 – Peter Cordes Dec 09 '22 at 02:12
  • 1
    @PeterCordes: ...or, considering that the code in the question doesn't use any of the above, just a `.model small, c` line, which is enough to let the code assemble. I haven't tested it (don't have a DOS VM, but my guess is that it'd run fine as well). Unless he was going to add something else, there's simply no need for a library. – Jerry Coffin Dec 09 '22 at 03:05
  • Thank you very much for all the help. Since I do not have any way to run a DOS VM or run this code, I'm looking into other options such as changing the code to run in 32-bit addressing. – cptalpdeniz Dec 09 '22 at 03:55
  • 2
    @cptalpdeniz: About the only way this works with 32-bit addressing is in a DOS extender (and it's not guaranteed even then--but with any other 32-bit environment I can think of, it's guaranteed to fail). – Jerry Coffin Dec 09 '22 at 04:14
  • 1
    That's how I see it as well, it's better to learn and work on a 32-bit addressing solution rather than trying to solve this with outdated methodology. – cptalpdeniz Dec 09 '22 at 04:17
  • @cptalpdeniz: https://docs.kernel.org/fb/framebuffer.html – Jerry Coffin Dec 09 '22 at 04:24