Lab Description:
The compiled assembly code is much more complex than the HLA code we did in Lab 2. In the assembly code all the “strings” in the HLA code are given their own labels and moved to the beginning of the code, and are jumped to when needed. After those labels, there is a ‘main’ label which holds the labels created for each loop used in the HLA code. Most of the syntax is the same besides the addition of an l at the end of some of the commands (ex: mov in assembly is movl) and a noticeable increase in the use off the call command. I could match most of the labels to the corresponding loops in the HLA code but the rest of the assembly code baffles me.
Code:
C++ CODE
#include using namespace std; int main() { int x, y, z, i; cout<<"Enter 1 to add: \n"; cout<<"Enter 2 to subtract: \n"; cout<<"Enter 3 to multiply: \n"; cout<<"Enter 4 to exponentiate: \n"; cout<<"Enter 5 to convert to roman numerals: \n"; cin>>x; switch(x) { case 1: cout<<"Enter number 1: "; cin>>x; if(x>65536) { cout<<"This number is too large.\n"; break; } else cout<<"Enter number 2: \n"; cin>>y; z=x+y; cout<<"The answer is "<<z<<endl; break; case 2: cout<<"Enter number 1: "; cin>>x; if(x>65536) { cout<<"This number is too large.\n"; break; } else cout<<"Enter number 2: \n"; cin>>y; z=x-y; cout<<"The answer is "<<z<<endl; break; case 3: cout<<"Enter number 1: "; cin>>x; if(x>65536) { cout<<"This number is too large.\n"; break; } else cout<<"Enter number 2: \n"; cin>>y; z=x*y; cout<<"The answer is "<<z<<endl; break; case 4: cout<<"Enter number 1: "; cin>>x; if(x>65536) { cout<<"This number is too large.\n"; break; } else cout<<"Enter number 2: \n"; cin>>y; for(i=y;i>0;y--) { z=x*x; } cout<<"The answer is "<<z<<endl; break; case 5: cout<<"Enter a decimal number or Enter 0 to exit.\n"; cin>>x; while(x!=0) { while(x!=0) { if(x>=1000) { cout<<"M"; x=x-1000; } else if(x>=900) { cout<<"CM"; x=x-900; } else if(x>=500) { cout<<"D"; x=x-500; } else if(x>=400) { cout<<"CD"; x=x-400; } else if(x>=100) { cout<<"C"; x=x-100; } else if(x>=90) { cout<<"XC"; x=x-90; } else if(x>=50) { cout<<"L"; x=x-50; } else if(x>=40) { cout<<"XL"; x=x-40; } else if(x>=10) { cout<<"X"; x=x-10; } else if(x>=9) { cout<<"IX"; x=x-9; } else if(x>=5) { cout<<"V"; x=x-5; } else if(x>=4) { cout<<"IV"; x=x-4; } else if(x>=1) { cout<<"I"; x=x-1; } } } } }
ASSEMBLY CODE
.file "newcalc.cpp" .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .section .rodata .LC0: .string "Enter 1 to add: \n" .LC1: .string "Enter 2 to subtract: \n" .LC2: .string "Enter 3 to multiply: \n" .LC3: .string "Enter 4 to exponentiate: \n" .align 8 .LC4: .string "Enter 5 to convert to roman numerals: \n" .LC5: .string "Enter number 1: " .LC6: .string "This number is too large.\n" .LC7: .string "Enter number 2: \n" .LC8: .string "The answer is " .align 8 .LC9: .string "Enter a decimal number or Enter 0 to exit.\n" .LC10: .string "M" .LC11: .string "CM" .LC12: .string "D" .LC13: .string "CD" .LC14: .string "C" .LC15: .string "XC" .LC16: .string "L" .LC17: .string "XL" .LC18: .string "X" .LC19: .string "IX" .LC20: .string "V" .LC21: .string "IV" .LC22: .string "I" .text .globl main .type main, @function main: .LFB963: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 subq $16, %rsp movl $.LC0, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl $.LC1, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl $.LC2, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl $.LC3, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl $.LC4, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %eax cmpl $5, %eax ja .L2 mov %eax, %eax movq .L8(,%rax,8), %rax jmp *%rax .section .rodata .align 8 .align 4 .L8: .quad .L2 .quad .L3 .quad .L4 .quad .L5 .quad .L6 .quad .L7 .text .L3: movl $.LC5, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %eax cmpl $65536, %eax jle .L9 movl $.LC6, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc jmp .L2 .L9: movl $.LC7, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -16(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %edx movl -16(%rbp), %eax leal (%rdx,%rax), %eax movl %eax, -4(%rbp) movl $.LC8, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -4(%rbp), %edx movl %edx, %esi movq %rax, %rdi call _ZNSolsEi movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi movq %rax, %rdi call _ZNSolsEPFRSoS_E jmp .L2 .L4: movl $.LC5, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %eax cmpl $65536, %eax jle .L10 movl $.LC6, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc jmp .L2 .L10: movl $.LC7, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -16(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %edx movl -16(%rbp), %eax movl %edx, %ecx subl %eax, %ecx movl %ecx, %eax movl %eax, -4(%rbp) movl $.LC8, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -4(%rbp), %edx movl %edx, %esi movq %rax, %rdi call _ZNSolsEi movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi movq %rax, %rdi call _ZNSolsEPFRSoS_E jmp .L2 .L5: movl $.LC5, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %eax cmpl $65536, %eax jle .L11 movl $.LC6, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc jmp .L2 .L11: movl $.LC7, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -16(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %edx movl -16(%rbp), %eax imull %edx, %eax movl %eax, -4(%rbp) movl $.LC8, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -4(%rbp), %edx movl %edx, %esi movq %rax, %rdi call _ZNSolsEi movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi movq %rax, %rdi call _ZNSolsEPFRSoS_E jmp .L2 .L6: movl $.LC5, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -12(%rbp), %eax cmpl $65536, %eax jle .L12 movl $.LC6, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc jmp .L2 .L12: movl $.LC7, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -16(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi movl -16(%rbp), %eax movl %eax, -8(%rbp) jmp .L13 .L14: movl -12(%rbp), %edx movl -12(%rbp), %eax imull %edx, %eax movl %eax, -4(%rbp) movl -16(%rbp), %eax subl $1, %eax movl %eax, -16(%rbp) .L13: cmpl $0, -8(%rbp) setg %al testb %al, %al jne .L14 movl $.LC8, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -4(%rbp), %edx movl %edx, %esi movq %rax, %rdi call _ZNSolsEi movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi movq %rax, %rdi call _ZNSolsEPFRSoS_E jmp .L2 .L7: movl $.LC9, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc leaq -12(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi call _ZNSirsERi jmp .L15 .L29: movl -12(%rbp), %eax cmpl $999, %eax jle .L17 movl $.LC10, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $1000, %eax movl %eax, -12(%rbp) jmp .L16 .L17: movl -12(%rbp), %eax cmpl $899, %eax jle .L18 movl $.LC11, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $900, %eax movl %eax, -12(%rbp) jmp .L16 .L18: movl -12(%rbp), %eax cmpl $499, %eax jle .L19 movl $.LC12, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $500, %eax movl %eax, -12(%rbp) jmp .L16 .L19: movl -12(%rbp), %eax cmpl $399, %eax jle .L20 movl $.LC13, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $400, %eax movl %eax, -12(%rbp) jmp .L16 .L20: movl -12(%rbp), %eax cmpl $99, %eax jle .L21 movl $.LC14, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $100, %eax movl %eax, -12(%rbp) jmp .L16 .L21: movl -12(%rbp), %eax cmpl $89, %eax jle .L22 movl $.LC15, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $90, %eax movl %eax, -12(%rbp) jmp .L16 .L22: movl -12(%rbp), %eax cmpl $49, %eax jle .L23 movl $.LC16, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $50, %eax movl %eax, -12(%rbp) jmp .L16 .L23: movl -12(%rbp), %eax cmpl $39, %eax jle .L24 movl $.LC17, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $40, %eax movl %eax, -12(%rbp) jmp .L16 .L24: movl -12(%rbp), %eax cmpl $9, %eax jle .L25 movl $.LC18, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $10, %eax movl %eax, -12(%rbp) jmp .L16 .L25: movl -12(%rbp), %eax cmpl $8, %eax jle .L26 movl $.LC19, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $9, %eax movl %eax, -12(%rbp) jmp .L16 .L26: movl -12(%rbp), %eax cmpl $4, %eax jle .L27 movl $.LC20, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $5, %eax movl %eax, -12(%rbp) jmp .L16 .L27: movl -12(%rbp), %eax cmpl $3, %eax jle .L28 movl $.LC21, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $4, %eax movl %eax, -12(%rbp) jmp .L16 .L28: movl -12(%rbp), %eax testl %eax, %eax jle .L16 movl $.LC22, %esi movl $_ZSt4cout, %edi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc movl -12(%rbp), %eax subl $1, %eax movl %eax, -12(%rbp) .L16: movl -12(%rbp), %eax testl %eax, %eax setne %al testb %al, %al jne .L29 .L15: movl -12(%rbp), %eax testl %eax, %eax setne %al testb %al, %al jne .L16 .L2: movl $0, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE963: .size main, .-main .type _Z41__static_initialization_and_destruction_0ii, @function _Z41__static_initialization_and_destruction_0ii: .LFB972: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 subq $16, %rsp movl %edi, -4(%rbp) movl %esi, -8(%rbp) cmpl $1, -4(%rbp) jne .L31 cmpl $65535, -8(%rbp) jne .L31 movl $_ZStL8__ioinit, %edi call _ZNSt8ios_base4InitC1Ev movl $_ZNSt8ios_base4InitD1Ev, %eax movl $__dso_handle, %edx movl $_ZStL8__ioinit, %esi movq %rax, %rdi call __cxa_atexit .L31: leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE972: .size _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii .type _GLOBAL__I_main, @function _GLOBAL__I_main: .LFB973: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 movl $65535, %esi movl $1, %edi call _Z41__static_initialization_and_destruction_0ii leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE973: .size _GLOBAL__I_main, .-_GLOBAL__I_main .section .ctors,"aw",@progbits .align 8 .quad _GLOBAL__I_main .weakref _ZL20__gthrw_pthread_oncePiPFvvE,pthread_once .weakref _ZL27__gthrw_pthread_getspecificj,pthread_getspecific .weakref _ZL27__gthrw_pthread_setspecificjPKv,pthread_setspecific .weakref _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_,pthread_create .weakref _ZL20__gthrw_pthread_joinmPPv,pthread_join .weakref _ZL21__gthrw_pthread_equalmm,pthread_equal .weakref _ZL20__gthrw_pthread_selfv,pthread_self .weakref _ZL22__gthrw_pthread_detachm,pthread_detach .weakref _ZL22__gthrw_pthread_cancelm,pthread_cancel .weakref _ZL19__gthrw_sched_yieldv,sched_yield .weakref _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t,pthread_mutex_lock .weakref _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t,pthread_mutex_trylock .weakref _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec,pthread_mutex_timedlock .weakref _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t,pthread_mutex_unlock .weakref _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t,pthread_mutex_init .weakref _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t,pthread_mutex_destroy .weakref _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t,pthread_cond_broadcast .weakref _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t,pthread_cond_signal .weakref _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t,pthread_cond_wait .weakref _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec,pthread_cond_timedwait .weakref _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t,pthread_cond_destroy .weakref _ZL26__gthrw_pthread_key_createPjPFvPvE,pthread_key_create .weakref _ZL26__gthrw_pthread_key_deletej,pthread_key_delete .weakref _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t,pthread_mutexattr_init .weakref _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti,pthread_mutexattr_settype .weakref _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t,pthread_mutexattr_destroy .ident "GCC: (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292]" .section .comment.SUSE.OPTs,"MS",@progbits,1 .string "ospwg" .section .note.GNU-stack,"",@progbits