Question1. (lesson 2) In the following code we determine a number if its even or odd. Explain...

70.2K

Verified Solution

Question

Programming

Question1. (lesson 2)

In the following code we determine a number if its even or odd.Explain what logic is used for that?   

section .text

   global_start           ;must be declared for using gcc

      

_start:                    ;tell linker entry point

   mov   ax,  8h          ;getting 8 in the ax

   and   ax,1             ;and ax with 1

   jz    evnn

   mov   eax,4            ;system call number (sys_write)

   mov   ebx,1            ;file descriptor (stdout)

   mov   ecx,odd_msg       ;message to write

   mov   edx,len2          ;lengthof message

   int  0x80              ;call kernel

   jmp   outprog

evnn:  

  

   mov   ah, 09h

   mov   eax,4            ;system call number (sys_write)

   mov   ebx,1            ;file descriptor (stdout)

   mov   ecx,even_msg      ;message to write

   mov   edx,len1          ;lengthof message

   int  0x80              ;call kernel

outprog:

   mov  eax,1             ;system call number (sys_exit)

   int  0x80              ;call kernel

section   .data

even_msg db 'Even Number!' ;message showing even number

len1 equ $ - even_msg

   

odd_msg db 'Odd Number!'    ;message showing oddnumber

len2 equ $ - odd_msg

                    

Question 2. (lesson 1 and lesson 3)

                   Write a program that does thefollowing(modification from assignment 3)

           1. Asks the user to enter two numbers (each is a byte) A and B

           2. Multiply the numbers and stores the result in variable C.

                 3. so that if theproduct  exceeds 10, the program would print “result isgreater than 10”.

                     Otherwise (if result < 10), it prints the result as usual.

Answer & Explanation Solved by verified expert
3.8 Ratings (698 Votes)
First question To find whether a number a number is even or odd we check its least significant bit in binary representaion If the Least Significant Bit is 1 the number is odd otherwise it is even Here AND operation is performed between the    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students