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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:34:27+00:00 2026-06-06T15:34:27+00:00

Write a NASM macro: divide, which has 2 arguments, which specify unsigned integers in

  • 0

Write a NASM macro: divide, which has 2 arguments, which specify unsigned integers in any addressing mode. The macro computes the ceiling of its first argument, divided by its second argument, and places the result in register edx. If the second argument is 0 (to be tested at runtime), the result should be 0, and a message “divide by zero” should be printed to stdout.

This is the code I wrote. How to write this code without labels? (position independs code)

%macro divide 2

section .rodata
        LC1: DB "divide by zero ", 10, 0

section .text

  mov eax, %1
  mov ebx, %2
  cmp ebx, 0 ; divide by zero
  jne rest1
  push LC1
  call printf
  add esp,4
  mov edx, 0
  jmp end1

rest1:
  mov edx, 0
  div ebx
  add eax, edx
  mov edx , eax ; the result should be in edx

end1:
 %endmacro
  • 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-06T15:34:28+00:00Added an answer on June 6, 2026 at 3:34 pm

    There’s quite a difference between “no labels” and “position-independent code”. You can have one, but not the other, you can have both, you can have neither.

    It’s not very easy to make the above code without labels. And I see no good reason why you would want that. Can you explain what you’re doing, the bigger goals behind this task?

    It’s also unusual to make position-independent macros. Normally, things like an entire subroutine are made position-independent. Again, why do you think you need it?

    Nonetheless, all jump and call instructions in the above code are eip-relative (see the details of the jmp/jcc and call instructions in the documentation).

    For that reason jne rest1 and jmp end1 don’t make the macro position-dependent. These jumps always advance eip by a constant amount, irrespective of where the code is located.

    OTOH, for that same reason call printf (and possibly push LC1) do(es) make the macro position-dependent. You can avoid this by passing the addresses of printf and LC1 into the macro as additional arguments (either explicit (as with other two arguments) or implicit (e.g. in some predefined place, register or stack location)).

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

Sidebar

Related Questions

Write a NASM macro: divide, which has 2 arguments, which specify unsigned integers in
Write a function lv: cfg -> (blabel -> ide set) , which computes the
Write a predicate sorted(L) which tests whether a list of integers is sorted, [n1,n2,...,nk]
Write a function which has: input: array of pairs (unique id and weight) length
I write the following program in NASM in order to practice offset, addressing, tables,
Write a function called swap which has a prototype of void swap (int&, int&);
Write a class ListNode which has the following properties: int value; ListNode *next; Provide
I wanted to write something basic in assembly under Windows. I'm using NASM, but
write a script that takes two optional boolean arguments,--verbose‚ and ‚--live, and two required
I write app for Android which will be communicate with HTTP server. I need

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.