Question

In: Computer Science

Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding...

Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding in NASM on a SASM system.

Solutions

Expert Solution

;; x86 intel 32 assembly language
section .data
        msg1 db "Even no. from 1 to 20",10,0
        msg db "%d",10,0
section .text
        global main   ;for gcc compiler we use function name main
        extern  printf  ;  printf is builtin function of c
main:
        push msg1
        call printf     ; pritnt the msg1
        add esp,4
        
        mov ecx,1       ;move 1 into ecx register for counter purpose
        mov ebx,2       ;move 2 into ebx for dividing by 2
        mov eax,1       ;eax stores the number which we are going to check even
        
lp1:    xor edx,edx      ; remainder is stored in edx register by default
        div  ebx         ;divide eax by ebx
        cmp edx,0        ;check remainder is zero or not
        jz printn        ; if remainder is zero then jmp to label printn and print that number
        
prev:   inc ecx         ; increment counter
        mov eax,ecx     ;get the next no in eax register
        cmp ecx,21      ;compair with 21
        jl lp1          ;if ecx is less that 21 then jump to lable lp1
        ret             ;if not  less then exit from code
        
printn: pusha              ;push all cureent values of registers into stack because after calling printf values get modified
        push ecx         ; push value of ecx into stack
        push msg        ;push msg  into stack
        call printf     ;call printf function
        add esp,8       ;add 8 in stack pointer i.e. esp register
        popa             ;pop all values of registeres that was push by pusha instruction
        jmp prev        ;jump to label prev to check next no.

Related Solutions

I am to write a code that uses two queues, and print the generated random numbers...
I am to write a code that uses two queues, and print the generated random numbers and content of both queues. I need to use the enqueue and dequeue functions in the code.  The instructions are below. Program should be in C Instructions: Generate n random numbers with values between 10 - 100. Note: n>9 if u write a function (for example, called generateRand) to do this - what is the data or input we have to give it? Create a...
Please submit a screenshot of where your code got compiled, executed, showing the execution result Write...
Please submit a screenshot of where your code got compiled, executed, showing the execution result Write a program/function in python that will perform the following functions, when the program is executed, to demonstrate the features of an OOP language—ADT, inheritance, and polymorphism: Prompt a list of options—the main menu, below to compute the area of selected shape with input parameters: triangle rectangle square circle parallelogram Exit Per the selected option, prompt grader to enter the corresponding required parameters as described...
Examples Example 1: Write pseudo code that reads two numbers and multiplies them together and print...
Examples Example 1: Write pseudo code that reads two numbers and multiplies them together and print out their product. Example 2: Write pseudo code that tells a user that the number they entered is not a 5 or a 6. Example 3: Write pseudo code that performs the following: Ask a user to enter a number. If the number is between 0 and 10, write the word blue. If the number is between 10 and 20, write the word red....
I want to convert those codes to assembler code // Problem 1 // for loop J=5...
I want to convert those codes to assembler code // Problem 1 // for loop J=5 for(i=1; i<5; i++) {         j-- } // Problem 2 // if - then - else i=4 if (i < 5) then         j = 3 else         j = 2 // Problem 3 //while loop i = 0 j = 0 while(i==0) {   j++   if j = 5 then         i = j }
Fill in the blanks of this code to print out the numbers 1 through 7. number...
Fill in the blanks of this code to print out the numbers 1 through 7. number = 1 while number ___ 7:     print(number, end=" ")     ___
I am trying to write a code in C for a circuit board reads in a...
I am trying to write a code in C for a circuit board reads in a temperature from a sensor on the circuit board and reads it onto a 7-segment LED display. How exactly would you code a floating 2 or 3 digit reading onto the LED display? I am stuck on this part.
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., 12321 This is the code i have, but it doesnt work. PLEASE MAKE SURE IT WORK BEFORE POST ANSWER, I GOT @ CODE THAT DID WORK BEFORE HTML JavaScript Palindrome Exercise rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" /> Palindrome Enter a positive number: Is this a palindrome? No...
I have the following assignment for probability class: I am supposed to write a routine (code)...
I have the following assignment for probability class: I am supposed to write a routine (code) in MATLAB that does solve the following problem for me: a) Generate N=10000 samples of a Uniform random variable (X) using the rand () command. This Uniform RV should have a range of -1 to +3. b) Generate (Estimate) and plot the PDF of X from the samples. You are not allowed to use the Histogram () command, any commands from the Matlab Statistics...
Question 1 Please, write a loop to print even members of an array a with pointers....
Question 1 Please, write a loop to print even members of an array a with pointers. You can use a variable “size” for array size Example Input: 1,2,5,6,8,9 Output : 2,6,8 Question 6 Please, write a loop to print odd numbers an array a with pointers backwards. You can use a variable “size” for array size Example Input: 1,2,5,6,8,9 Output : 9,5, Question2 1 LINKED LIST QUESTIONS For the following two questions you need to provide a code in C...
I am trying to write the code for an 8 bit adder in VHDL so that...
I am trying to write the code for an 8 bit adder in VHDL so that I can program it onto my Elbert V2 Spartan 3A FPGA Development Board, but I keep getting errors. Any ideas what I am doing wrong? library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity adder8bit is Port ( a : in STD_LOGIC_VECTOR(7 downto 0); b : in STD_LOGIC_VECTOR(7 downto 0); cin : in STD_LOGIC; o : out STD_LOGIC_VECTOR(7 downto 0); cout : out STD_LOGIC); end adder8bit; architecture Behavioral...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT