Перевести программу с Паскаля на Ассемблер - Assembler

Узнай цену своей работы

Формулировка задачи:

Помогите пожалуйстаа
program p;
var
a,b,c,d:real;
begin
writeln('Перевод RUB в USD - введите 1');
writeln('Перевод USD в RUB - введите 2');
readln(d);
writeln('Введите сумму перевода');
readln(a);
writeln('Введите курс USD к RUB');
readln(b);
if d=1 then begin
c:=a/b;
writeln(a:2:5,' RUB = ',c:2:5,' USD');
end
else if d=2 then
begin
c:=a*b;
writeln(a:2:5,' USD = ',c:2:5,' RUB');
end;
end.
хоть подскажите плииииз

Решение задачи: «Перевести программу с Паскаля на Ассемблер»

textual
Листинг программы
global  main
extern  printf
extern  scanf
 
section .text 
main: 
        push    msg1
        call    printf
        add     esp, 4
 
        push    d
        push    scn1
        call    scanf
        add     esp, 8
 
        push    msg2
        call    printf
        add     esp, 4
 
        push    a
        push    scn2
        call    scanf
        add     esp, 8
 
        push    msg3
        call    printf
        add     esp, 4
 
        push    b
        push    scn3
        call    scanf
        add     esp, 8
       
        mov     eax, [d]
        sub     eax, 1
        jz      M1
 
        fld     QWORD [b]
        fld     QWORD [a]
        fmulp   st1
        fstp    QWORD [c]
 
        push    DWORD [c+4]
        push    DWORD [c]
        push    DWORD [a+4]
        push    DWORD [a]
        push    msg4b
        call    printf
        add     esp, 20
 
        jmp     ME
M1:
        fld     QWORD [a]
        fld     QWORD [b]
        fdivp   st1
        fstp    QWORD [c]
 
        push    DWORD [c+4]
        push    DWORD [c]
        push    DWORD [a+4]
        push    DWORD [a]
        push    msg4a
        call    printf
        add     esp, 20
 
ME:
        
        xor     eax, eax
        ret
 
section .data 
msg1    db "Перевод RUB в USD - введите 1", 10
        db "Перевод USD в RUB - введите 2", 10, 0
scn1    db "%d", 0
msg2    db "Введите сумму перевода", 10, 0
scn2    db "%lf", 0
msg3    db "Введите курс USD к RUB", 10, 0
scn3    db "%lf", 0
msg4a   db "%lf RUB = %lf USD", 10, 0
msg4b   db "%lf USD = %lf RUB", 10, 0
 
section .bss
d       resd 1
a       resq 1
b       resq 1
c       resq 1

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 4 из 5