Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING NASM SYNTAX One use of the rcl and rcr instructions is in multiprecision a

ID: 3722002 • Letter: U

Question

USING NASM SYNTAX

One use of the rcl and rcr instructions is in multiprecision arithmetic.

For example, the 8086 is limited to 16-bits, so how could one represent a 32 bit number? The obvious way is to use two 16 bit registers.  

For example, if an unsigned 32-bit number, named A, is stored in dx:ax (top 16 bits in dx, and the lower 16 bits in ax) we could multiply A by 2 by using a left shift followed by a rotate through carry left as follows:
   shl ax,1
   rcl dx,1

Write a NASM program which will:
1. Display your name on the screen
2. Prompt the user to enter a 32-bit base-2 number from the keyboard.
3. Read the number, storing it into the register pair dx:bx.
4. On a new line, display an appropriate label and the number as a 32-bit binary number.
5. Ask the user if he/she wishes to read and display another number, and repeat from step 2 until the user is done.

Explanation / Answer

1) A sample Program to display your name on the screen:

           

_start:             ; states linker entrance point

   mov edx, len     ; defines length of the message

   mov ecx, msg     ; to write the message

   mov ebx,1       ; for standard output

   mov eax,4       ;for system write

   int     0x80        ;to call kernel

           

   mov eax, 1       ;for system exit

   int     0x80        ;to call kernel

section .data

msg db ‘Enter your name', 0xa ; for printing the given data on console

len equ $ - msg     ; to get the string length

2) The following code which is used to reads the number from the keyboard and display it on the console:

section .data                           ; for Data segment

   userMsg db 'Please enter a number: ' ;User going to give the number from keyboard

   lenUserMsg equ $-userMsg             ;to find the length of the message

   dispMsg db 'The entred value is: '

   lenDispMsg equ $-dispMsg                

section .bss           ;Declared data

   num resb 10

           

section .text          ;Code Segment

   global _start

           

_start:                ; prompt for user

   mov eax, 6

   mov ebx, 4

   mov ecx, userMsg

   mov edx, lenUserMsg

   int 80h

   ;The user input is going to read and store.

   mov eax, 7

   mov ebx, 3

   mov ecx, num

   mov edx, 10          ;10 bytes of information is going to allocated

   int 80h

           

   'The given or entered value is: '

   mov eax, 6

   mov ebx, 4

   mov ecx, dispMsg

   mov edx, lenDispMsg

   int 80h

   ;Output the number entered

   mov eax, 7

   mov ebx, 3

   mov ecx, num

   mov edx, 10

   int 80h

   

   ; Exit code

   mov eax, 1

   mov ebx, 0

   int 80h