o-eMSNOutlook, Office, Skype.. ee235Labo1 18F-EE 23A4/23. Assembly LAnguage main
ID: 3749170 • Letter: O
Question
o-eMSNOutlook, Office, Skype.. ee235Labo1 18F-EE 23A4/23. Assembly LAnguage main.asm EE235 Lab 1 (Fall 2018) Subject: Program loop Description: Write a program to add up all the odd numbers between 1 to 100. Example, Hint: Two probable ways to solve the problem. You can come up with your own. 1. You can store the numbers in memory then read and add them. (See practice from lab 0) 2. Starting from 1 you can generate the numbers by adding 2 with the current number Update your sum as sum+current number. Loop till the current number is greater than 100 Requirement 1. 2. Demonstrate that your program is working. Write a lab report that includes your name and techid, flow chart (or algorithm) Keep it with you when your TA is grading. 3. Upload your code to D2L (Filename: txt) before you show your code to TA. If you have multiple files, place them in a folder, zip it and upload it to d2l. Due date: 1. Program demo: September 12(Wednesday section) and September 17 (M section) onday 2. Lab Report: During lab demo Note: This is an individual lab assignmentExplanation / Answer
x86 assembly :-
section .text
global _start
_start:
mov edx, 0
mov eax, 1
.L_ODD_ADD:
add edx, eax
mov ebx, 2
add eax, ebx
cmp eax, 101
jl .L_ODD_ADD
mov eax, edx
; Convert EAX to ASCII and store it onto the stack
sub esp, 16 ; reserve space on the stack
mov ecx, 10
mov ebx, 16
.L1:
xor edx, edx ; Don't forget it!
div ecx ; Extract the last decimal digit
or dl, 0x30 ; Convert remainder to ASCII
sub ebx, 1
mov [esp+ebx], dl ; Store remainder on the stack (reverse order)
test eax, eax ; Until there is nothing left to divide
jnz .L1
mov eax, 4 ; SYS_WRITE
lea ecx, [esp+ebx] ; Pointer to the first ASCII digit
mov edx, 16
sub edx, ebx ; Count of digits
mov ebx, 1 ; STDOUT
int 0x80 ; Call 32-bit Linux
add esp, 16 ; Restore the stack
mov eax, 1 ; SYS_EXIT
xor ebx, ebx ; Return value
int 0x80 ; Call 32-bit Linux
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.