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...
Instructions:  Code a for statement that increments from 1 through 10, but print only the even numbers...
Instructions:  Code a for statement that increments from 1 through 10, but print only the even numbers using a fall-thru switch. You can catch the odd numbers using the option in the switch that handles everything else. Name your program ForFallThruSwitch.java. Use Java Style Guide in line advancing and spacing. --------------------OUTPUT RESULTS-------------------- Not printing odd numbers! 2 is an even number. Not printing odd numbers! 4 is an even number. Not printing odd numbers! 6 is an even number. Not printing...
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...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please...
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please count and print how many even numbers you have found.
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
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....
Write a c++ code that prompts the user to enter three float numbers and print them...
Write a c++ code that prompts the user to enter three float numbers and print them in acsending order
1. Write the code to show the current weather based on geolocation. I am stuck and...
1. Write the code to show the current weather based on geolocation. I am stuck and cant figure out how to show the weather. My current code is below. Please try and use OpenweatherAPI.   <!DOCTYPE html> <html>   <head>     <title>Weather</title>     <link       rel="stylesheet"       href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css"     />     <link rel="stylesheet" href="main.css" />     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>     <script type="text/javascript" src="app.js"></script>   </head>   <body>     <div class="jumbotron">       <button onclick="getLocation()">Get my location.</button>       <p id="demo"></p>       <script>         var x = document.getElementById("demo");         function getLocation() {           if (navigator.geolocation) {             navigator.geolocation.getCurrentPosition(showPosition);           } else {             x.innerHTML = "Geolocation...
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 }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT