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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:38:41+00:00 2026-05-26T19:38:41+00:00

For science fair, I need three programs that count to 50,000 and output each

  • 0

For science fair, I need three programs that count to 50,000 and output each number as they do, I need one in c++, one in java, and one in assembly. I have the c++ and java programs, but I don’t see what I’m doing wrong for my assembly code:

    [org 0x100]
    [bits 32]

    mov ax, 0
    mov bx, target
    jmp start

    start:
    mov cx, 0x01
    add ax, cx
    mov dx, ax
    mov ah, 09
    int 0x21
    mov ax, dx
    cmp ax, bx
    jg term
    jmp start

    term:
    mov dx, msgT
    mov ah, 09
    int 0x21
    mov ah, 00
    int 0x21

    msgT db 'Terminating'
    target dw 50000

I am using the assembler NASM, and right now, it counts to 50,000 but doesn’t output each number as it calculates them.

  • 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-26T19:38:42+00:00Added an answer on May 26, 2026 at 7:38 pm

    Copied from my comment:

    If you’re trying to make a 16-bit MS-DOS com file, you should be using [bits 16]. And as @Vlad says AH=09h takes a string in DX not a number (see e.g. here on how to convert a number to string, also note that you’ll have to $-terminate the string instead of NUL-terminate it).

    Some other things:

    • mov bx, target moves the address of target to bx. You wanted: mov bx, [target].
    • jg term is branching based on signed comparison (you’re effectively comparing ax to -15536). You want ja term.
    • You need to make sure to preserve the number, keeping it in a register requires extreme care. It’s easier to just save it on the stack.

    The basic structure of your program should be something like this:

        [org 0x100] ; DOS .COM files are loaded at CS:0100h
        [bits 16]   ; And are 16-bits
    
    start:
        mov ax, 0          ; The current count
    printloop:
        push ax            ; Save current number 
    
        call myconvertfunc ; Some function to convert a number in ax and return a '$'-terminated string in dx
        mov ah, 0x09
        int 0x21
    
        mov dx, newline    ; Point dx to newline string
        mov ah, 0x09       ; Print $-terminated string in dx
        int 0x21
    
        pop ax             ; Restore current number
    
        inc ax             ; Next number 
        cmp ax, 50000      ; Compare number to the maximum number 
        jbe printloop      ; Notice branching based on unsigned comparison is needed
    
        mov ax, 0x4c00     ; Return 0. AH=4Ch AL=Return value
        int 0x21
    
    newline: db 13, 10, '$' ; String containing "\r\n$"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my computer science class, we need to write a program (in C++) that
There's a computer science term for this that escapes my head, one of those
My little brother is just getting into programming, and for his Science Fair project,
I'm a non-computer science student doing a history thesis that involves determining the frequency
Our computer science teacher once said that for some reason it is faster to
Brief: When academic (computer science) papers say "O(polylog(n))", what do they mean? I'm not
In my book (for my computer science course) they have source code snippets. We're
I am following The Art and Science of Java book and it shows how
At Computer Science lecture we’ve been told that there’s a special code (lower that
Background: for my computer science class, we were asked to create a program that

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.