Hello I need help converting this 16bit code into a 32bit code for my assembly l
ID: 3886934 • Letter: H
Question
Hello I need help converting this 16bit code into a 32bit code for my assembly language class can anyone help. code below.
Thanks
TITLE sumsqr ;sum of squares
;----------------------------------------------------
.MODEL SMALL
.STACK 64 ;define stack
.DATA ;define data
pala1 DW 21h
pala2 DW
17h pala3 DB ?
pala4 DB ?
pala5 DW ?
;_______________________________________________
.CODE ; define code segment
MAIN PROC FAR
;Startup initializes data
MOV ax,@data ;set address of data
MOV ds,ax
mov ax,pala1
mov bx,pala1
mul bx
mov bx,ax
mov ax,pala2
mul ax
add ax,bx
mov pala3,al
mov pala4,ah
mov ah,06h ;clear screen
mov al,00h ;full screen
mov bh,48h ;page 157
mov cx,0000h ;starting row;column
mov dx,184fh ;ending row column
int 10h
mov ah,02h ;set cursor
mov bh,00h ;page number zero
mov dh,17 ;line number
mov dl,25 ;column number
int 10h
mov dl,pala4
int 21h
mov dl,pala3
int 21h
mov ax,4c00h;end processing
;Exit
INT 21h
MAIN ENDP
END MAIN
Explanation / Answer
There is major difference in bit32 programming and bit 16 programming of Assembly Languages.
Here I am explaining changes you required to in your program only.
Before going to make changes in program, under stands the basic difference in programming ways
1.In 32 bits programming,
2.In 32 bit Assembly programming System calls are used to perform different task like sys_write to print the result,
sys_exit for exit the program and many more.
3.To operate on these system calls you need to follow following steps
· ECX,EDX,EBX,ESI,EDI and EBP registers can be used to store arguments for system call.
· call the relevent interrupt.
So these are some basic helpful in converting this program.
Start with Program
TITLE sumsqr ;sum of squares
;----------------------------------------------------
Title and Comments lines are remained as it is
.MODEL SMALL
.STACK 64 ;define stack
There is no need to declare these statements. Directly can start with data section
.DATA ;define data
pala1 DW 21h
pala2 DW 17h
In bit 32 programming data section starts with section.data in place of .DATA
section.data
pala1 DW 21h
pala2 DW 17h
The uninitialized variables are defined with reserving memory for them.
For this we use section.bss section
pala3 DB ?
defined as
pala3: .space 2
pala4 DB ?
pala4 .space 2
pala5 DW ?
pala5 .space 4
The Start of program and initilization is to be done in following way
replace following code with
.CODE ; define code segment
MAIN PROC FAR
;Startup initializes data
MOV ax,@data ;set address of data
MOV ds,ax
In 32bit programming
section.text
global_start
_start:
This code give the starting point of program.
Now the calculation the register like AX,BX should be replaced with EAX,EBX
mov ax,pala1
mov bx,pala1
mul bx
mov bx,ax
mov ax,pala2
mul ax
add ax,bx
so according to bit 32 ,
mov eax,pala1
mov ebx,pala1
mul ebx
mov ebx,eax
mov eax,pala2
mul eax
add eax,ebx
Next , to clear screen ,full screen or to make set on screen you can use following code as it is or you may skip as well,this does not related to logic
mov ah,06h ;clear screen
mov al,00h ;full screen
mov bh,48h ;page 157
mov cx,0000h ;starting row;column
mov dx,184fh ;ending row column
int 10h
mov ah,02h ;set cursor
mov bh,00h ;page number zero
mov dh,17 ;line number
mov dl,25 ;column number
int 10h
Now need to make changes to output the result
mov dl,pala4
int 21h
is replaced with
mov edx,pala4
mov ebx,1 ;file descriptor
mov eax,4 ;sys_write system call
int 0x80 ;call the kernel
Similarly
mov dl,pala3
int 21h
is replaced with
mov edx,pala3
mov ebx,1 ;file descriptor
mov eax,4 ;sys_write system call
int 0x80 ;call the kernel
The exit code will be like
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.