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

  • Home
  • SEARCH
  • 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 7730077
In Process

The Archive Base Latest Questions

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

I’m using NASM 16 BITS. I’m trying to do a simple assembly code that

  • 0

I’m using NASM 16 BITS. I’m trying to do a simple assembly code that prints the numbers from 0 to 255 with 1 second interval between each number. This is what I have so far:

[bits 16]

mov ax,cs
mov ds,ax
mov cx,255
mov ax,0

myloop:
    ;print in screen ax value
    ;wait 1 second
    inc ax

loop myloop

I’m not sure how to print the value of ax in the screen, and how to wait 1 second(placed them in a comment in 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-06-01T06:07:58+00:00Added an answer on June 1, 2026 at 6:07 am

    There’s a 4-byte counter at segment 0 offset 46Ch (or alternatively at seg 40h, offs 6Ch) maintained and updated by the PC BIOS. It’s incremented 18.2 times per second. Counting 18 changes in the lowest byte or word of this counter is probably the simplest way of waiting out approximately a second:

    mov  ax, 0
    mov  ds, ax
    mov  cx, 18
    mov  bx, [46Ch]
    WaitForAnotherChange:
    NoChange:
    mov  ax, [46Ch]
    cmp  ax, bx
    je   NoChange
    mov  bx, ax
    loop WaitForAnotherChange
    

    To print decimal numbers you need to convert binary numbers into decimal, get individual digits and print them. You divide the number by 10 and collect remainders. e.g.:

    123:
    123 / 10: quotient 12, remainder 3
    12 / 10: quotient 1, remainder 2
    1 / 10: quotient 0, remainder 1

    By repeatedly dividing by 10 you get the individual digits in the remainders in the reverse order: 3,2,1. Then you print them using DOS int 21h function 2 (load 2 into AH, load the character’s ASCII code into DL, execute int 21h).

    An alternative variant, quite suited to your problem, would be to use the DAA instruction to increment the number directly in decimal without any conversion.

    Here’s how it all can be done:

    ; file: counter.asm
    ; assemble: nasm.exe counter.asm -f bin -o counter.com
    
    bits 16
    org 0x100
    
        mov  ax, 0 ; initial number
        mov  cx, 256 ; how many numbers
    
    NextNumber:
    %if 1 ; change to 0 to use the DAA-based method
        push ax
    
        mov  dx, 0
        div  word [ten]
        push dx
    
        mov  dx, 0
        div  word [ten]
        push dx
    
        mov  dx, 0
        div  word [ten]
        push dx
    
        pop  dx
        call PrintDigit
        pop  dx
        call PrintDigit
        pop  dx
        call PrintDigit
    
        pop  ax
    
        call PrintNewLine
        call Wait1s
    
        inc  ax
    %else
        mov  dl, ah
        call PrintDigit
    
        mov  dl, al
        shr  dl, 4
        call PrintDigit
    
        mov  dl, al
        and  dl, 0Fh
        call PrintDigit
    
        call PrintNewLine
        call Wait1s
    
        add  al, 1
        daa
        adc  ah, 0
    %endif
    
        loop NextNumber
        ret
    
    PrintDigit:
        pusha
        mov   ah, 2
        add   dl, '0'
        int   21h
        popa
        ret
    
    PrintNewLine:
        pusha
        mov   dx, CRLF
        mov   ah, 9
        int   21h
        popa
        ret
    
    Wait1s:
        pusha
        push ds
    
        mov  ax, 0
        mov  ds, ax
    
        mov  cx, 18
        mov  bx, [46Ch]
    WaitForAnotherChange:
    NoChange:
        mov  ax, [46Ch]
        cmp  ax, bx
        je   NoChange
        mov  bx, ax
        loop WaitForAnotherChange
    
        pop  ds
        popa
        ret
    
    ten dw 10
    CRLF db 13,10,"$"
    

    If you don’t like the leading zeroes or the last 1-second delay, you can conditionally skip them.

    Download Intel and/or AMD x86 CPU manuals that describe how each instruction works. Read them. Also, download the Ralf Brown's Interrupt List, which describes every BIOS and DOS function. You need to know some of them to do I/O. There are also HelpPC and TechHelp that conveniently describe many BIOS and DOS things like the BIOS Data Area where the aforementioned counter lives.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.