Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone rewrite this assembly code so it doesnt look the same but still does the same thing. (program i use is Visual Studio) These

Can someone rewrite this assembly code so it doesnt look the same but still does the same thing. (program i use is Visual Studio)

These libraries are needed for the C library functions. INCLUDELIB msvcrtd INCLUDELIB legacy_stdio_definitions INCLUDELIB ucrt

; Normal directives .386 .model flat, C .stack 100h

; Prototypes printf PROTO argl : Ptr Byte, printlist : VARARG exit PROTO errorCode : DWORD scanf PROTO argl : Ptr Byte, scanlist : VARARG srand PROTO arg1 : SDWORD rand PROTO system PROTO arg1 : Ptr Byte time PROTO seconds:PTR DWORD getchar PROTO arg1 : PTR byte

.data ;Printf strings astr byte "*" , 0 ;Asterisks, empty highmsg byte "Energy levels too high, must move." , 0 lowmsg byte "Energy levels okay." , 0 rng1msg byte "0000-4095:" , 0 rng2msg byte "4096-8191:" , 0 rng3msg byte "8192-12287:", 0 rng4msg byte "12288-16383:" , 0 rng5msg byte "16384-20479:" , 0 rng6msg byte "20480-24575:" , 0 rng7msg byte "24576-28671:" , 0 rng8msg byte "28672-32767:" , 0 choice byte "Please enter 0 to quit or any other number to scan again." , 0 clear byte "cls" , 0

;scanf format in1fmt byte 0Ah, "%d" , 0

;printf formats msg1fmt byte 0Ah, "%s" , 0 astrfmt byte "%s" , 0 clearfmt byte "%d" , 0Ah, 0

;Variables rng1 DWORD ? rng2 DWORD ? rng3 DWORD ? rng4 DWORD ? rng5 DWORD ? rng6 DWORD ? rng7 DWORD ? rng8 DWORD ? choi DWORD ? null DWORD NULL count DWORD ? print DWORD ? divamt DWORD 32768 rngct DWORD ? i DWORD ?

.code main PROC INVOKE time, ADDR null INVOKE srand , eax

reset:

;resets counters to 0 mov rng1, 0 mov rng2, 0 mov rng3, 0 mov rng4, 0 mov rng5, 0 mov rng6, 0 mov rng7, 0 mov rng8, 0 mov count, 0

randomize: ;increases count and checks if particle has reached 10,000. inc count mov eax, count cmp eax, 10000 ja print1

;Gets a random value and starts in into the correst range counter. INVOKE rand cdq idiv divamt mov eax, edx cmp eax, 4095

ja range2 inc rng1 jmp randomize range2: cmp eax, 8192 ja range3 inc rng2 jmp randomize range3: cmp eax, 12287 ja range4 inc rng3 jmp randomize range4: cmp eax, 16383 ja range5 inc rng4 jmp randomize range5: cmp eax, 20479 ja range6 inc rng5 jmp randomize range6: cmp eax, 24575 ja range7 inc rng6 jmp randomize range7: cmp eax, 28671 ja range8 inc rng7 jmp randomize range8: inc rng8 jmp randomize

;Prints graph ranges print1: INVOKE printf, ADDR msg1fmt, ADDR rng1msg mov eax, rng1 mov rngct, eax jmp astrprint print2: INVOKE printf, ADDR msg1fmt, ADDR rng2msg mov eax, rng2 mov rngct, eax jmp astrprint print3: INVOKE printf, ADDR msg1fmt, ADDR rng3msg mov eax, rng3 mov rngct, eax jmp astrprint print4: INVOKE printf, ADDR msg1fmt, ADDR rng4msg mov eax, rng4 mov rngct, eax jmp astrprint print5: INVOKE printf, ADDR msg1fmt, ADDR rng5msg mov eax, rng5 mov rngct, eax jmp astrprint print6: INVOKE printf, ADDR msg1fmt, ADDR rng6msg mov eax, rng6 mov rngct, eax jmp astrprint print7: INVOKE printf, ADDR msg1fmt, ADDR rng7msg mov eax, rng7 mov rngct, eax jmp astrprint print8: INVOKE printf, ADDR msg1fmt, ADDR rng8msg mov eax, rng8 mov rngct, eax jmp astrprint

;Puts a counter value into EAX and prints asteriks. astrprint: mov eax, rngct cmp eax, 100 jb check1 INVOKE printf, ADDR astrfmt, ADDR astr sub rngct, 100 jmp astrprint ;Checks for asterisks 50 and up. check1: inc print cmp eax, 50 jb printnext INVOKE printf, ADDR astrfmt, ADDR astr

;Changes to the correct bar statement printnext: mov eax, print cmp eax, 2 je print2 cmp eax, 3 je print3 cmp eax, 4 je print4 cmp eax, 5 je print5 cmp eax, 6 je print6 cmp eax, 7 je print7 cmp eax, 8 je print8

;Sums all ranges above 16383 to see if they exceed 5000 mov eax, rng5 add eax, rng6 add eax, rng7 add eax, rng8 cmp eax, 5000 jb safe INVOKE printf, ADDR msg1fmt, ADDR highmsg jmp restart safe: INVOKE printf, ADDR msg1fmt, ADDR lowmsg

;Ccontinue or quit choice check restart: INVOke printf, ADDR msg1fmt, ADDR choice INVOKE scanf, ADDR in1fmt, ADDR choi mov eax, choi cmp eax, 0 jz final mov i, 0

clrscr: INVOKE printf, ADDR clearfmt, i INVOKE system, ADDR clear inc i mov eax, i cmp eax, 10 jae reset

jmp clrscr

final: INVOKE exit, 0

main ENDP

END main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago