Can someone help me for this. Please write this in X86 assembly language COMMENT
ID: 673422 • Letter: C
Question
Can someone help me for this. Please write this in X86 assembly language
COMMENT!
a. Create a constant for the number of minutes in an hour
b. Prompt the user for the starting time and read in the user input
c. Prompt the user for the ending time and read in the user input
The user input has 2 digits for hour, 2 digits for minutes.
For example: 0930 for 9:30am, or 2208 for 10:08pm
The range of input hour is 0 - 23, and the range of input minute is 0 - 59
d. Calculate the time difference between the starting and ending times,
make sure to use the constant of step a
e. Print the difference as number of hours and number of minutes
Make sure there is a text explanation, such as: 2 hr 9 min
The time difference can be negative if the starting time is later than the ending time
Except for text string variables, the program should have no other memory variables
Given the range of data used in the program, use the smallest data size (not DWORD)
Explanation / Answer
There are several directives that we use to define the constants.Some of them are listed below:-
1)EQU
2)%assign
3)%define
A]Seconds EQU (any default value)
This line creates the constants seconds and any default value can be provided for the variable defined above.
B] Prompt the user for the starting time.
This code have been taken by compiling the C code and after disassembling it from the online editor.
.Ltext0:
.section
.rodata
.LC0:
.string "Enter the starting time"
movl $.LC0, %edi
movl $0, %eax
call printf
leaq -4(%rbp), %rdx
leaq -8(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
C]
Prompt the user for the end time.
Similarly this also have been added by disassembling.
.Ltext0:
.section
.rodata
.LC0:
.string "Enter the ending time"
movl $.LC0, %edi
movl $0, %eax
call printf
leaq -4(%rbp), %rdx
leaq -8(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
[D and I have consolidated the entire code into one,it have all the parts in it.To ensure the code is running I have done so.
The entire code which performs the explanation is given below:-
.Ltext0:
.section .rodata
.LC0:
.string "Enter the starting time"
.LC1:
.string "%d"
.LC2:
.string "Enter the ending time"
.text
.globl main
main:
.LFB0:
.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 $.LC0, %edi
movl $0, %eax
call printf
leaq -8(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
movl -8(%rbp), %eax
movl %eax, %edi
call convert_format
movl %eax, -8(%rbp)
movl $.LC2, %edi
movl $0, %eax
call printf
leaq -4(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
movl -4(%rbp), %eax
movl %eax, %edi
call convert_format
movl %eax, -4(%rbp)
movl -4(%rbp), %edx
movl -8(%rbp), %eax
movl %edx, %esi
movl %eax, %edi
call difft
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.globl convert_format
convert_format:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
cmpl $1299, -4(%rbp)
jle .L3
movl -4(%rbp), %eax
subl $1200, %eax
jmp .L4
.L3:
cmpl $99, -4(%rbp)
jg .L5
movl -4(%rbp), %eax
addl $1200, %eax
jmp .L4
.L5:
movl -4(%rbp), %eax
.L4:
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.section .rodata
.LC3:
.string "Difference is "
.LC4:
.string "The difference is %d"
.text
.globl difft
difft:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movl %edi, -20(%rbp)
movl %esi, -24(%rbp)
movl $0, -4(%rbp)
movl -24(%rbp), %eax
movl -20(%rbp), %edx
subl %eax, %edx
movl %edx, %eax
movl %eax, -4(%rbp)
cmpl $0, -4(%rbp)
jle .L9
movl -4(%rbp), %eax
movl %eax, %esi
movl $.LC3, %edi
movl $0, %eax
call printf
jmp .L10
.L9:
movl -4(%rbp), %eax
negl %eax
movl %eax, %esi
movl $.LC4, %edi
movl $0, %eax
call printf
.L10:
movl -4(%rbp), %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE2:
.Letext0:
The code given above is the output after it has been diassembled into the Assembly language.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.