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 1061599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:29:49+00:00 2026-05-16T18:29:49+00:00

Here is my short assembly program: ; This code has been generated by the

  • 0

Here is my short assembly program:

; This code has been generated by the 7Basic
; compiler <http://launchpad.net/7basic>

extern printf

; Initialized data

      SECTION .data
f_0 dd 5.5
printf_f: db "%f",10,0

      SECTION .text

; Code

global main
  main:
push ebp
mov ebp,esp

push dword [f_0]
push printf_f
call printf
add esp,8

mov esp,ebp
pop ebp
mov eax,0
ret

What the program is supposed to do is print 5.5, but it prints:

-4101885043414705786563701568963176764603483495211119243453355953219830430011006780068899468997203661787555969981250050126586203424320244681571103387315766489883301796219461838644670607029711305942610787622864198879363376953745160639821663444829839767678538571371627347101810056161000273217639447052410683392.000000

What on earth am I doing wrong? The code is pushing the two arguments to printf() and then calling it. Nothing complicated.


Update: I was a little premature in thinking I had fixed this. I have updated the code.

  • 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-05-16T18:29:50+00:00Added an answer on May 16, 2026 at 6:29 pm

    The instruction push f_0 pushes the address of f_0 on the stack, not the 5.5 in memory there, so the printf routine will take the address, plus the saved ebp (the next 4 bytes on the stack) and interpret the bits as a double and print it out. That turns out to be a very large number, as you see.

    You need to load 8 bytes from f_0 and push those. something like

    move eax, f_0
    push dword ptr [eax+4]
    push dword ptr [eax]
    

    edit

    You need to push 8 bytes as fp64 values are 8 bytes. fp64 is all that printf knows how to print — in fact fp64 is all that C knows how to pass to functions or operate on. fp32 value can only be loaded from and stored to memory, but are always implicitly converted to fp64 (or larger) before being operated on. If you want to load an fp32 value, convert it fp64, and push it on the stack, you can use

    fld dword ptr [f_0]
    sub esp, 8
    fstp qword ptr [esp]
    

    This actually loads an fp32 value and converts it to fp80 (the x87’s internal format), then converts that fp80 value to fp64 and stores it on the stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT DISTINCT t.Person, f.Food FROM MyTable AS t CROSS APPLY(… May 16, 2026 at 11:10 pm
  • Editorial Team
    Editorial Team added an answer It looks like PHP 5.3's DateInterval supports this. If you… May 16, 2026 at 11:10 pm
  • Editorial Team
    Editorial Team added an answer You can put this category code whereever you like. In… May 16, 2026 at 11:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've inherited a 10K-line program written in 8051 assembly language that requires some changes.
I've got some library code that works on a range of .NET runtimes (regular,
Here is a very simplified program which reproduces the issue I faced in the
While writing some C code, I decided to compile it to assembly and read
I've been trying to figure this for a few days now, with no luck.
Here's the top of my usercontrol: <UserControl x:Class=MyApp.Common.Controls.Views.SimpleView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:Framework=http://www.memoryexpress.com/UIFramework mc:Ignorable=d
I have some questions about the following code: using System; namespace ConsoleApplication2 { public
This is a Bad Idea, I know, but... I want to configure log4net programmatically
Basically, my question is short and sweet: Is the following a bad idea (encapsulating
I am writing some small program in C--some log in, log out, create account,

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.