I am a high school student, and this year I started learning assembly.
I am currently making a Pacman clone as my final project.
The only issue that I'm having is that my code is big, and the *.exe file is almost at 64KB.
So my question is, if I move to model medium, what do I need to do to make my code work with the extra code segment?
I think that I need to use Icall instead of call, and update the procedures since now every time that I call them both the segment and ip get pushed, but is there anything else that I need to do?
If you work in a model with more than one code segment, every code pointer becomes a 32 bit pointer. That means:
call and ret, you need to use call far and ret far (this is something the assembler might do for you)call far pushes a four byte return address on the stack, so you need to adjust the offsets for fetching argumentsFor your purpose, it might be enough to just use the small model, that is, one segment for code and one for data and stack. This way, your executable can be up to 128 kB in size. The small model is very similar to the tiny model in that you can mostly ignore segmentation unless you need to read/write data from the text segment.
For medium model (multiple code segments, one data segment), jumps within a code segment will be small (16 bit offset), jumps between code segments will be far (32 bit segment:offset). For functions that are only called within the same code segment, they can be declared as near and a near call (16 bit offset) will be used. Example code for Masm 6.x, the call and return for nearfun uses near call and return, the call and return for farfun uses far call and return.
.286
.model medium
.stack 1024
.code one ;code segment named "one"
main proc far
call nearfun ;call near function
call farfun ;call far function
mov ax,04c00h ;exit to dos
int 21h
main endp
nearfun proc near
mov ax,1
ret
nearfun endp
.code two ;code segment named "two"
farfun proc far
mov ax,2
ret
farfun endp
end main
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With