Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:33:58+00:00 2026-06-01T06:33:58+00:00

Im trying to use printf in my assembley code in model large, and i

  • 0

Im trying to use printf in my assembley code in model large, and i get a fixup overflow, what do i need to change in this code to make it work?

.MODEL LARGE
.STACK 100h
.DATA
int     DW "%d"
.CODE
.386

extrn   _printf:far
PUBLIC _stack_protection
_stack_protection PROC FAR
push    bp          
mov bp,sp           
push    es
mov     ax,10
push    ax
push    word ptr int
call    _printf
add sp,4
pop es  
pop bp          
ret 
_stack_protection ENDP
    END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:33:59+00:00Added an answer on June 1, 2026 at 6:33 am

    You need to change this:

    int     DW "%d"
    

    to this:

    _int     DB "%d",0
    

    Because printf() expects normal, NUL-terminated C strings, because C strings consist of bytes, not words and because int is likely a reserved word (at least it is in TASM).

    You also need to change this:

    push    word ptr int
    ...
    add sp,4
    

    to this:

    push    seg _int
    push    offset _int
    ...
    add sp,6
    

    Because in the large memory model all pointers are far, that is, consist of a segment and an offset.

    So, this is what I end up with…

    Asm file:

    ; file: larg.asm
    ; how to assemble: tasm.exe /ml larg.asm
    .MODEL LARGE
    
    ;.STACK 100h ; unnecessary and too small anyway,
    ; let the C compiler take care of it
    
    DATA segment word public 'DATA' ; make sure class='DATA' (default)
    ;int     DW "%d" ; 'int' is a reserved word,
    ; C strings must consist of bytes/chars and end with byte 0
    _int    DB "%d", 0
    DATA ends
    
    extrn   _printf:far ; for some reason this must be
    ; outside of the code segment
    
    CODE segment byte public 'CODE' USE16 ; make sure it's
    ; 16-bit code, class='CODE' (default)
    assume cs:CODE
    .386
    
    PUBLIC _stack_protection
    _stack_protection PROC FAR
    push    bp
    mov     bp,sp
    push    es
    mov     ax,10
    push    ax
    ;push    word ptr int ; must be the far address of '_int'
    ; because in the 'large' memory model all pointers are 'far'
    push    seg _int
    push    offset _int
    call    _printf
    ;add sp,4 ; must account for the far address size on stack
    add     sp,6
    pop     es
    pop     bp
    ret
    _stack_protection ENDP
    CODE ends
    
        END
    

    C file:

    // file: large.c
    // how to compile: tcc.exe -mlarge large.c larg.obj
    
    #include <stdio.h>
    
    extern void stack_protection(void);
    
    int main(void)
    {
      stack_protection();
      printf("\n");
      return 0;
    }
    

    I then compile the program (with Turbo C++ 1.01 and TASM 3.2):

    tasm.exe /ml larg.asm
    tcc.exe -mlarge large.c larg.obj
    

    And run it:

    c:\large.exe
    10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I am trying to use mysqli in object orientated way, this is the code:
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I am trying to use md5 code to calculate checksums of file. Now the
In a for loop, I am trying to use printf to print the current
I'm trying to use the Win32 API to make a sub-thread that reads from
I'm trying to use rusage statistics in my program to get data similar to
I am trying to use the SetParametersInfo function to change wallpapers.I would like to
I'm trying use double type in openCL, but doesn't work anyway, i want use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.