Rewrite the following java program in assembly language using mars. /** This pro
ID: 3568464 • Letter: R
Question
Rewrite the following java program in assembly language using mars.
/**
This program is designed to take the total amount a customer owes and subtract it from what he has
paid and then determine how much change he will recive. in the form of dollars, nickel, quarter, dimes,
and pennies
*/
import java.util.Scanner;
public class Belton
{
public static void main (String[] args)
{
double amtDue; // Amount that must be paid
double amtPay; // Amount given to cashier
double change; // Amount to be given back to the customer
int customers; // Number of customers
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the number of customers?");
customers= keyboard.nextInt();
for (int count =1;count<=customers;count++)
{
System.out.println("Processing Customer " + count);
System.out.println("What is the amount of your purchase?");
amtDue = keyboard.nextDouble();
System.out.println("How much did you pay?");
amtPay = keyboard.nextDouble();
change = amtPay - amtDue;
System.out.println(" Your change is: " + change);
System.out.println("Thanks for shopping with us! Come again soon.");
}
}
}
Explanation / Answer
.Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.section
.rodata
.align 8
.LC0:
.string "Please enter the number of customers?"
.LC1:
.string "Processing Customer "
.align 8
.LC2:
.string "What is the amount of your purchase?"
.LC3:
.string "How much did you pay?"
.LC4:
.string " Your change is: "
.align 8
.LC5:
.string "Thanks for shopping with us! Come again soon."
.text
.globl main
main:
.LFB971:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
.cfi_lsda 0x3,.LLSDA971
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
.LBB2:
movl $.LC0, %esi
movl $_ZSt4cout, %edi
.LEHB0:
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
leaq -32(%rbp), %rax
movq %rax, %rsi
movl $_ZSt3cin, %edi
call _ZNSirsERi
.LBB3:
movl $1, -28(%rbp)
jmp .L2
.L3:
movl $.LC1, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl -28(%rbp), %edx
movl %edx, %esi
movq %rax, %rdi
call _ZNSolsEi
movl $.LC2, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
leaq -24(%rbp), %rax
movq %rax, %rsi
movl $_ZSt3cin, %edi
call _ZNSirsERd
movl $.LC3, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
leaq -16(%rbp), %rax
movq %rax, %rsi
movl $_ZSt3cin, %edi
call _ZNSirsERd
movsd -16(%rbp), %xmm0
movsd -24(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -8(%rbp)
movl $.LC4, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movq %rax, %rdx
movq -8(%rbp), %rax
movq %rax, -40(%rbp)
movsd -40(%rbp), %xmm0
movq %rdx, %rdi
call _ZNSolsEd
movl $.LC5, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
.LEHE0:
addl $1, -28(%rbp)
.L2:
movl -32(%rbp), %eax
cmpl %eax, -28(%rbp)
jle .L3
.LBE3:
movl $0, %eax
jmp .L7
.L6:
movq %rax, %rdi
.LEHB1:
call _Unwind_Resume
.LEHE1:
.L7:
.LBE2:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
.globl __gxx_personality_v0
.section
.gcc_except_table,"a",@progbits
.LLSDA971:
.byte 0xff
.byte 0xff
.byte 0x1
.uleb128
.LLSDACSE971-
.LLSDACSB971
.LLSDACSB971:
.uleb128 .LEHB0-.LFB971
.uleb128 .LEHE0-.LEHB0
.uleb128 .L6-.LFB971
.uleb128 0
.uleb128 .LEHB1-.LFB971
.uleb128 .LEHE1-.LEHB1
.uleb128 0
.uleb128 0
.LLSDACSE971:
.text_Z41__static_initialization_and_destruction_0ii:
.LFB977:
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L8
cmpl $65535, -8(%rbp)
jne .L8
.L8:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE977: _GLOBAL__sub_I_main:
.LFB978:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE978:
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.text
.Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.