Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is an assembly code for muliply and division. can someone explain why my debug for dx say 2 0 0 0 , ax for

here is an assembly code for muliply and division. can someone explain why my debug for dx say 2000, ax for 13107, eax for 858993459, and edx for 2000? The code is correct but I don't understand why ax dx eax and edx are in those numbers. please explain by using calculations. Thank you!(gdb) b _start imull %eax #multipli eax bu itself
#After imull, eax=1000*1000=1000000
#edx:eax=0:1000000(since the result fits in eax, edx is zero)
movw opWord, sax #load opWord(100) into ax
movw opWord, sdx #load opWord(100) into dx
idivw sourceWord #divide dx:ax by sourceWord(4000)
#before idivw, dx:ax=100*100
#idivw sourceWord(4000)
#Quotient=(dx:ax)/sourceWord=(100:100)/4000
#Qoutieny=1(ax), remainder =100(dx)
movl opLong, seax #Load opLong(1000) into eax
movl opLong, sedx #Load opLong(1000) into edx
idivl sourceLong #divide edx:eax by sourceLong(5000)
#before idivl, edx:eax=1000:1000
#idivl sourceLong(5000)
#Quotient =(edx:eax)/sourceLong =(1000:1000)/5000
done:
nop
Function "_start" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1(_start) pending.
(gdb) P $dx
(gdb) b
Breakpoint 2 at 0x8049036
(gdb) P $ax
(gdb) b
Note: breakpoint 2 also set at pc 0x8049036,
Breakpoint 3 at 0x8049036
(gdb) P $dx
(gdb) p $eax
(gdb) p $edx
(gdb)
.data
opByte: .byte 8
opWord: .word 100
opLong: .long 1000
sourceByte: .byte 64
sourceWord: .word 4000
sourceLong: .long 5000
.text
.global _main
_main:
movw opWord, %ax #Load opWord(100) into ax
imulw %ax #multiply ax by itself
#After imulw, ax=100*100=10000
#dx:ax=0:10000(since the result fits in eax, dx is zero)
movl opLong, %eax #Load opLong(1000) into eax
imull %eax #multipli eax bu itself
#After imull, eax=1000*1000=1000000
#edx:eax=0:1000000(since the result fits in eax, edx is zero)
movw opWord, %ax #load opWord(100) into ax
movw opWord, %dx #load opWord(100) into dx
idivw sourceWord #divide dx:ax by sourceWord(4000)
#before idivw, dx:ax=100*100
#idivw sourceWord(4000)
#Quotient=(dx:ax)/sourceWord=(100:100)/4000
#Qoutieny=1(ax), remainder =100(dx)
movl opLong, %eax #Load opLong(1000) into eax
movl opLong, %edx #Load opLong(1000) into edx
idivl sourceLong #divide edx:eax by sourceLong(5000)
#before idivl, edx:eax=1000:1000
#idivl sourceLong(5000)
#Quotient =(edx:eax)/sourceLong =(1000:1000)/5000
#Quotient =0, remainder =1000(edx)
done:
nop
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions