Решение арифметического выражения ( X*Y )+( X/Y ) / X-Y - Assembler
Формулировка задачи:
В задании необходимо вывести решение выражения
(( X*Y )+( X/Y )) / X-Y
, при условии что,X - WORD Y - DWORD
. Тупые вопросы тут не любят, но что поделать самостоятельно вдуплить работу с регистрами не очень получается, хотелось бы узнать где я ошибся? выдаёт совершенно не тоformat PE console entry start include 'include\win32a.inc' section '.idata' import data readable library kernel,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getchar,'_fgetchar' section '.data' data readable writeable X dw 100 ; x - word Y dd 50 ; y - dword MESSAGE db "Result is %d",0dh,0ah,0 MESSAGE2 db "ostatok is %d",0dh,0ah,0 section '.code' code readable executable start: ; x*y (1) xor eax, eax mov ax,[X] mul ax ; edx:eax = x*y push edx push eax ; x\y (2) xor edx, edx xor ebx, ebx mov edx, [Y] adc bx, 0 mov bx, [X] div ebx ; eax = x/y ( edx:eax / ebx) ; pop ecx ; x*y + x/y (3) add eax, ecx adc edx, 0 ; x-y (4) sub ebx, [Y] ; x-y ;(x*y + x/y)/x-y (5) div ebx ; edx:eax = (x*y + x/y)/x-y ccall [printf], MESSAGE, eax ccall [getchar] stdcall [ExitProcess],0
Решение задачи: «Решение арифметического выражения ( X*Y )+( X/Y ) / X-Y»
textual
Листинг программы
format PE console entry start include 'include\win32a.inc' section '.idata' import data readable library kernel,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getchar,'_fgetchar' section '.data' data readable writeable X dw 100 ; x - word Y dd 50 ; y - dword MESSAGE db "Result is %d",0dh,0ah,0 MESSAGE2 db "ostatok is %d",0dh,0ah,0 section '.code' code readable executable start: ; x*y (1) mov ax,[X] ;ax=[X] cwde ;eax=[X] imul dword [Y] ; edx:eax = x*y push edx push eax ; x\y (2) mov ax,[X] cwde cdq ;(edx:eax)=[X] idiv dword[Y] ; eax = x/y ( edx:eax / [Y]) ; ; x*y + x/y (3) pop ecx pop edx add eax, ecx adc edx, 0 ; x-y (4) push eax mov ax, [X] cwde sub eax, [Y] ; x-y mov ebx, eax pop eax ;(x*y + x/y)/x-y (5) idiv ebx ; edx:eax = (x*y + x/y)/x-y ccall [printf], MESSAGE, eax ccall [getchar] stdcall [ExitProcess],0
Объяснение кода листинга программы
Coded written in Assembler language.
- X and Y are the variables used in the calculation. X is a word and Y is a dword. Initial value of X and Y are 100 and 50 respectively.
- The first part of the calculation is x*y. Result is stored in edx:eax.
- The second part of the calculation is x/y. Result is stored in eax.
- The third part of the calculation is (x*y + x/y). Result is stored in eax.
- The fourth part of the calculation is x-y. Result is stored in eax.
- The fifth part of the calculation is (x*y + x/y)/x-y. Result is stored in edx:eax.
- The program uses the function printf to print the message
Result is %d\n
with the result of the calculation as the parameter. - The program uses the function getchar to pause the program and wait for user input.
- The program calls the ExitProcess function to exit the program.
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д