MPLab 32bit Multiplication
Jump to navigation
Jump to search
32-bit Binary Multiplication
1. Define the model and architecture for the assembly code
.model small .stack 100H .386 ; specifies that the program will use instructions of the 80386 processor (32-bit instructions).
2. Define your data in the data section ( here you can define various data items: variables, constants, strings, arrays)
.data ; .data directive indicates the beginning of data section ; DATA1 and DATA2 are 32-bit variables initialized to 0. DATA1 dd 00000000H DATA2 dd 00000000H ; PROD1 and PROD2 32-bit uninitialized variables. PROD1 dd ? PROD2 dd ? ;define strings that will be displayed as messages to the user while executing the program. msg db 10,13,"Enter the First Number: $" msg1 db 10,13,"Enter the Second Number: $" msg2 db 10,13,"The Product (in Hexadecimal) is: $"
3. Define your instruction in the code section (here you write the assembly instructions that perform computations, control program flow, and interact with data variables and memory)
.code ; .code directive indicates the beginning of code section .startup ; the entry point of the program
; Using DOS interrupt 21H to display the message. MOV AH,09 MOV DX,OFFSET msg INT 21H
; Read the First Number and store it into DATA1 MOV EBX, 0 MOV CX, 8 AGAIN: MOV AH, 01 ;1ST NO. ENTERED INT 21H CMP AL,'A' JGE L5 SUB AL,30H JMP L6 L5: SUB AL,37H L6: SHL EBX,4 ADD BL,AL LOOP AGAIN MOV DATA1, EBX