Friday, March 16, 2018

12. Write 80387 ALP to find the roots of the quadratic equation. All the possible cas es must be considered in calculating the roots.

section .data
msg1 db 10,13,"Complex Root"
msglen1 equ $-msg1

msg2 db 10,13," Root1: "
msglen2 equ $-msg2

msg3 db 10,13," Root2: "
msglen3 equ $-msg3

a dd 1.00
b dd 8.00
c dd 15.00
four dd 4.00
two dd 2.00

hdec dq 100
point db "."
      
section .bss
  
    root1 resd 1
    root2 resd 1
    resbuff rest 1
    temp resb 2
    disc resd 1

%macro write 2            ;macro for display
    mov rax,1
    mov rdi,1
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

%macro read 2            ;macro for input
    mov rax,0
    mov rdi,0
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

%macro exit 0            ;macro for exit
    mov rax,60
    xor rdi,rdi
    syscall
%endmacro

section .text
  global _start
  _start:

  finit                ; initialise 80387 co-processor
  fld dword[b]            ; stack: b

  
   
  fmul dword[b]             ; stack: b*b

  fld dword[a]            ; stack: a, b*b

  fmul dword[c]             ; stack: a*c, b*b

  fmul dword[four]        ; stack: 4*a*c,b*b

  fsub                 ; stack: b*b - 4*a*c

  ftst                 ; compares ST0 and 0
 
 
  fstsw ax                ;Stores the coprocessor status word ;into either a word in memory or the AX register
  sahf        ;Stores the AH register into the FLAGS register.
  jb no_real_solutions         ; if disc < 0, no real solutions
  fsqrt             ; stack: sqrt(b*b - 4*a*c)

  fst dword[disc]     ; store disc= sqrt(b*b - 4*a*c)

  fsub dword[b]                 ; stack: disc-b

  fdiv dword[a]             ; stack: disc-b/2*a or (-b+disc)/2a


  fdiv dword[two]

  write msg2,msglen2
 call disp_proc
  fldz                ;stack:0
  fsub dword[disc]        ;stack:-disc
  fsub dword[b]             ; stack: -disc - b
  fdiv dword[a]        ; stack: (-b - disc)/(2*a)
  fdiv dword[two]

  write msg3,msglen3
  call disp_proc
  jmp exi

no_real_solutions:
write msg1,msglen1
exi :

mov rax,60
mov rdi,1
syscall
    

disp_proc:
    FIMUL dword[hdec]
    FBSTP tword[resbuff]
    mov rsi,resbuff+9
    mov rcx,09
  next1:
    
      push rcx
      push rsi
    
      mov bl,[rsi]
      call disp
    
      pop rsi
      pop rcx
    
       dec rsi
      loop next1
    push rsi
      write point,1
    pop rsi
      mov bl,[rsi]
      call disp
    ret


disp:
        mov edi,temp                ;mov dnum address into edi
        mov ecx,02                    ;initialize ecx with 2
        dispup1:
            rol bl,4                ;rotate bl by 4 bits
            mov dl,bl                ;move bl into dl
            and dl,0fh            ;and of dl with 0fh
            add dl,30h            ;add 30h into dl
            cmp dl,39h            ;compare dl with 39h
            jbe dispskip1            ;jump if below and equal to dispskip1
            add dl,07h            ;add 7h into dl
            dispskip1:
                mov [edi],dl        ;mov dl into dnum
                inc edi            ;increament edi by a byte
            loop dispup1        ;loop dispup1 while ecx not zero
            write temp,2            ;Display dnum by calling macro
          ret                    ;return from procedure


OUTPUT:

swlab@swlab-H81-M1:~$ nasm -f elf64 square.asm
swlab@swlab-H81-M1:~$
ld -o mean mean.o
swlab@swlab-H81-M1:~$
./square Root1: 800000000000000003.00
Root2: 800000000000000005.00
swlab@swlab-H81-M1:~$

11. Write 80387 ALP to obtain: i) Mean ii) Variance iii) Standard Deviation Also plot the histogr am for the data set.

section .data

msg1 db 10,13,'mean is:  '
msg1len equ $- msg1

msg2 db 10,13, 'std deviation is:'
msg2len equ $- msg2

msg3 db 10,13, 'variance is:'
msg3len equ $- msg3

data dd 9.0,1.0
datacnt dw 02
hdec dq 100

decpt db '.'

section .bss

res rest 01
mean resd 01
var resd 01
dispbuff resb 01

%macro disp 2
    mov eax,04
    mov ebx,01
    mov ecx,%1
    mov edx,%2
    int 80h
%endmacro
%macro accept 2
    mov eax,03
    mov ebx,00
    mov ecx,%1
    mov edx,%2
    int 80h
%endmacro

section .text
global _start
_start:

disp msg1,msg1len
 
       finit
    fldz
    mov rbx,data
    mov rsi,00
    xor rcx,rcx
    mov cx,[datacnt]



bk:    fadd dword [rbx+rsi*4]
    inc rsi
    loop bk

    fidiv word[datacnt]
    fst dword[mean]
     
    call dispres

    MOV RCX,00
    MOV CX,[datacnt]
    MOV RBX,data
    MOV RSI,00
    FLDZ
up1:    FLDZ
    FLD DWORD[RBX+RSI*4]
    FSUB DWORD[mean]
    FST ST1
    FMUL
    FADD
    INC RSI
    LOOP up1
    FIDIV word[datacnt]
    FST dWORD[var]
    FSQRT

    disp msg2,msg2len
    CALL dispres

    FLD dWORD[var]
    disp msg3,msg3len
    CALL dispres
 
 
exit:     mov eax,01
    mov ebx,00
    int 80h

disp8_proc:
    mov rdi,dispbuff
    mov rcx,02
back:    rol bl,04
    mov dl,bl
    and dl,0FH
    cmp dl,09
    jbe next1
    add dl,07H
next1:  add dl,30H
    mov [rdi],dl
    inc rdi
    loop back
    ret
 
dispres:
    fimul dword[hdec]
    fbstp tword[res]
    xor rcx,rcx
    mov rcx,09H
    mov rsi,res+9
up2:    push rcx
    push rsi
    mov bl,[rsi]
    call disp8_proc
    disp dispbuff,2 
    pop rsi
    dec rsi
    pop rcx
    loop up2
    disp decpt,1

    mov bl,[res]
    call disp8_proc
    disp dispbuff,2 
    ret

OUTPUT:
swlab@swlab-H81-M1:~$ nasm -f elf64 mean.asm
swlab@swlab-H81-M1:~$ ld -o mean mean.o
swlab@swlab-H81-M1:~$ ./mean

mean is:  000000000000000005.00
std deviation is:000000000000000004.00
variance is:000000000000000016.00

swlab@swlab-H81-M1:~$

10. Write x86 ALP to find the factorial of a given integer number on a command line by using recursion. Explicit stack manipulation is expected in the code.

;Problem Statement: Write x86 ALP to find the factorial of a given integer ;number on a command line by using
;recursion. Explicit stack manipulation is expected in the code.


%macro scall 4   ;common macro for input/output
 mov rax,%1
 mov rdi,%2
 mov rsi,%3
 mov rdx,%4
 syscall
%endmacro

section .data
 num db 00h
 msg db "Factorial is : "
 msglen equ $-msg
 msg1 db "*****Program to find Factorial of a number***** ",0Ah
   db "Enter the number : ",
 msg1len equ $-msg1

 zerofact db " 00000001 "
 zerofactlen equ $-zerofact

section .bss
 dispnum resb 16
 result resb 4
 temp resb 3


section .text
global _start
_start:

 scall 1,1,msg1,msg1len
 scall 0,0,temp,3   ;accept number from user
 call convert       ;convert number from ascii to hex
 mov [num],dl

 scall 1,1,msg,msglen

 mov rdx,0        ;RMD
 mov rax,0        ;RMD
 mov al,[num]   ;store number in accumulator
 cmp al,01h 
 jbe endfact
 mov rbx,0        ;RMD
 mov bl,01h
 call factr    ;call factorial procedure
 call display

 call exit
endfact:
 scall 1,1,zerofact,zerofactlen
 call exit

 factr:    ;recursive procedure

   cmp rax,01h
   je retcon1
   push rax 
   dec rax
 
   call factr

  retcon:
   pop rbx
   mul ebx
   jmp endpr

  retcon1:   ;if rax=1 return
   pop rbx
   jmp retcon
  endpr:

 ret

 display:   ; procedure to convert hex to ascii

   mov rsi,dispnum+15
   mov rcx,0        ;RMD
   mov cl,16

  cont:
   mov rdx,0        ;RMD
   mov rbx,0        ;RMD
   mov bl,10h
   div ebx
   cmp dl,09h
   jbe skip
   add dl,07h
  skip:
   add dl,30h
   mov [rsi],dl
   dec rsi
   loop cont

   scall 1,1,dispnum,16

 ret

 convert:   ;procedure to convert ascii to hex
   mov rsi,temp
   mov cl,02h
   MOV rax,0        ;RMD
   mov rdx,0        ;RMD
  contc:
   rol dl,04h
   mov al,[rsi]
   cmp al,39h
   jbe skipc
   sub al,07h
  skipc:
   sub al,30h
   add dl,al
   inc rsi
   dec cl
   jnz contc

 ret

 exit:    ;exit system call
  
   mov rax,60
   mov rdi,0
   syscall

ret

OUTPUT:
swlab@swlab-Veriton-M200-H81:~/Desktop/dhokane$ nasm -f elf64 fact.asm
swlab@swlab-Veriton-M200-H81:~/Desktop/dhokane$ ld -o fact fact.o
swlab@swlab-Veriton-M200-H81:~/Desktop/dhokane$ ./fact
*****Program to find Factorial of a number*****
Enter the number : 03
Factorial is : 0000000000000006
swlab@swlab-Veriton-M200-H81:~/Desktop/dhokane$
 

9. Write a TSR to gene rate the pattern of the frequency tones by reading the Real Time Clock (RTC). The duration of the each tone is solely decided by the programmer.

code segment
assume cs:code
org 100h                ;prog seg prefix addrss
jmp initze              ;hex no of 256
savint dd ?             ;for saving address of es:bx
count dw 0000h          ;count of tics

hours db ?
mins db ?
sec db ?

testnum:
        push ax    ;store all the contents of register
        push bx    ;(not to change original values of register)
        push cx
        push dx
        push cs
        push es
        push si
        push di

        mov ax,0b800h   ;starting address of display
        mov es,ax
        mov cx,count
        inc cx
        mov count,cx
        cmp cx,011h
     
      jne exit

        mov cx,0000h
        mov count,cx
        call time
exit:
        pop di
        pop si
        pop es
        pop ds
        pop dx
        pop cx
        pop bx
        pop ax
        jmp cs:savint   ;jump to normal isr

;------------------convert procedure--------------------
convert proc
        and al,0f0h
        ror al,4
        add al,30h
        call disp
        mov al,dh
        and al,0fh
        add al,30h
        call disp
        ret
endp

;------------------------time procedure----------------
time proc
        mov ah,02h      ;getting current time system clk
        int 1ah
        mov hours,ch    ;HH->ch, MM->cl, SS->dh
        mov mins,cl
        mov sec,dh

       ; mov bx,0E00h    ;location for displaying clk
 
       mov bx,3984
        mov al,hours       ;Display Hours
        mov dh,hours
        call convert
        mov al,':'
        call disp

        mov al,mins       ;Display Mins
        mov dh,mins
        call convert
        mov al,':'
        call disp


        mov al,sec       ;Display Seconds
        mov dh,sec
        call convert
   
       call tone
 
       ret
         endp


;-----------------------display procedue----------------
disp proc
        mov ah,9Ch      ;for setting attribute
                 ;ATTRIBUTE BYTE  BL  R  G  B  I  R  G  B 
                                         ;BACKGROUND FOREGROUND
       mov es:bx,ax    ;write into vedio buffer
        inc bx
        inc bx
        ret
endp

;--------------- frequency tone procedure-------------------

tone proc

       mov     al, 182         ; Prepare the speaker for the
        out     43h, al         ;  note.
        mov     ax, 4560        ; Frequency number (in decimal)                             
        out     42h, al         ; Output low byte.
        mov     al, ah          ; Output high byte.
        out     42h, al
        in      al, 61h         ; Turn on note (get value from
                                ;  port 61h).
        or      al, 00000011b   ; Set bits 1 and 0.
        out     61h, al         ; Send new value.
        mov     bx, 25          ; Pause for duration of note.
.pause1:
        mov     cx, 65535
.pause2:
        dec     cx
        jne     .pause2
        dec     bx
        jne     .pause1
        in      al, 61h         ; Turn off note (get value from
                                ;  port 61h).
        and     al, 11111100b   ; Reset bits 1 and 0.
        out     61h, al         ; Send new value. 
       ret
endp
;------------------initialization------------------------
initze:
        push cs
        pop ds
        cli             ;clear int flag

        mov ah,35h      ;35 for get orignal add
        mov al,08h      ;intrrupt no
        int 21h
        mov word ptr savint,bx
        mov word ptr savint+2,es

        mov ah,25h              ;25 for set int add
        mov al,08h
        mov dx,offset testnum   ;new add for intrrupt
        int 21h

        mov ah,31h              ;make prog resident(request tsr)
        mov dx,offset initze    ;size of program

        sti                    ;set intrrupt flag
        int 21h               
code ends
end

OUTPUT:


8. Write X86 menu driven Assembly Language Program (ALP) to implement OS (DOS) commands TYPE, COPY and DELETE using file operations. User is supposed to provide command line arguments in all cases.

;***Guidelines for running program***
;create two file with name file1.txt and file2.txt
;first you have to enter your choice i.e. 1 or 2 or 3....
;then enter commands
;for type: command is type file1.txt
;for copy: command is copy file1.txt file2.txt
;for delete: command is delete file1.txt
;give first file name as file1.txt and second file name as file2.txt

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall

%endmacro

%macro iomodule 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro

%macro exit 0
mov rax,60
syscall
%endmacro

section .data
    cmd db 10,13, "command menu"
        db 10,13,"1.TYPE"
        db 10,13,"2.COPY"
        db 10,13,"3.DELETE"
        db 10,13,"4.EXIT"
        db 10,13,"Enter choice:"      
    len equ $ - cmd
    entercmd db 10,13,"Enter command:------: "
    cmdlen equ $ - entercmd
    msg0 db 10,13,"Failed to open the file!!!"
    len0 equ $ - msg0
    msg1 db 10,13,"File opened successfully!!!"
    len1 equ $ - msg1
    msg2 db 10,13,"Failed to open the file!!!"
    len2 equ $ - msg2
    msg3 db 10,13, "Command not found!!!!"
    len3 equ $ - msg3
  
section .bss
    buffer resb 200
    bufferlen resb 8
    choice resb 50
    chlen equ $ - choice
    fdis1 resb 200
    fdis2 resb 200
    cnt1 resb 2
    ch1 resb 2
    name1 resb 20
    name2 resb 20
    size resb 200
section .text
global _start
_start:
    print cmd, len
    accept ch1, 2
    mov rsi, ch1
    cmp byte[rsi], '1'
    je TYPE
    cmp byte[rsi], '2'
    je COPY
    cmp byte[rsi], '3'
    je DELETE
    cmp byte[rsi], '4'
    exit
    jmp error
  
TYPE:
    print entercmd, cmdlen
    accept choice, chlen
    mov rsi, choice
    mov byte[size], al
    dec byte[size]
    mov al, byte[rsi]
nd:
  
    cmp al, 't'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'y'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'p'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'e'
    jne error
    inc rsi
    dec byte[size]
  
    jmp success
error:
    print msg3, len3
    jmp _start
success:
    inc rsi
    dec byte[size]
    mov rdi, name1
top:
    mov al, byte[rsi]
    mov [rdi], al
    inc rdi
    inc rsi
    dec byte[size]
    jnz top
  
    iomodule 2, name1, 2, 777
    mov qword[fdis1], rax
    bt rax, 63
    jc error
  
    iomodule 0, [fdis1], buffer, 200
    mov qword[cnt1], rax
  
    iomodule 1, 1, buffer, qword[cnt1]
  
    mov rax, 3
    mov rdi, name1
    syscall
    jmp _start
  
DELETE:
    print entercmd, cmdlen
    accept choice, chlen
    mov byte[size], al
    dec byte[size]
    mov al, byte[rsi]
nd1:
    cmp al, 'd'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'e'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'l'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'e'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 't'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'e'
    jne error
    inc rsi
    dec byte[size]
    jmp success1
success1:
    inc rsi
    dec byte[size]
    mov rdi, name2
top1:
    mov al, byte[rsi]
    mov [rdi], al
    inc rdi
    inc rsi
    dec byte[size]
    jnz top1
  
    mov rax, 87
    mov rdi, name2
    syscall
    jmp _start
  
COPY:
    print entercmd, cmdlen
    accept choice, chlen
    mov byte[size], al
    dec byte[size]
    mov al, byte[rsi]
nd2:
    cmp al, 'c'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'o'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'p'
    jne error
    inc rsi
    dec byte[size]
    mov al, byte[rsi]
    cmp al, 'y'
    jne error
    inc rsi
    dec byte[size]
  
    jmp success2
success2:
        inc rsi
    dec byte[size]
    mov rdi, name1
    mov rcx, 9
nsp:
    mov al, [rsi]
    mov [rdi], al
    inc edi
    inc rsi
    dec byte[size]
    loop nsp
  
    inc rsi
    dec byte[size]
        xor rdi, rdi
    mov rdi, name2
nnl:
    mov al, [rsi]
    mov [rdi], al
    inc rdi
    inc rsi
    dec byte[size]
    jnz nnl

    iomodule 2, name1, 2, 777
    mov qword[fdis1], rax
  
  
    iomodule 0, [fdis1], buffer, 200
    mov qword[cnt1], rax
    iomodule 2, name2, 2, 777
    mov qword[fdis2], rax
  
    iomodule 1, [fdis2], buffer, qword[cnt1]
  
    mov rax, 3
    mov rdi, name1
    syscall
    mov rax, 3
    mov rdi, name2
    syscall

jmp _start
    exit


file1.txt
I am Prof. Dhokane R.M

file2.txt
I am Prof. Butkar U.D.

OUTPUT
swlab@swlab-H81-M1:~$ cd Desktop/
swlab@swlab-H81-M1:~/Desktop$ cd cmd/
swlab@swlab-H81-M1:~/Desktop/cmd$ nasm -f elf64 cmd.asm
swlab@swlab-H81-M1:~/Desktop/cmd$ ld -o cmd cmd.o
swlab@swlab-H81-M1:~/Desktop/cmd$ ./cmd

command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1

Enter command:------: type file1.txt
I am prof Butkar U.D.

command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1

Enter command:------: type file2.txt
I am prof Dhokane R.M.

command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
2

Enter command:------: copy file1.txt file2.txt

command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
3

Enter command:------: delete file1.txt

command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
4
swlab@swlab-H81-M1:~/Desktop/cmd$

7. Write X86 program to sort the list of integers in ascending/descending order. Read the input from the text file a nd write the sorted data back to the same text file using bubble sort

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro file 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro

Section .data
openmsg db 10,13,"File Opened Successfully"
openmsg_len equ $-openmsg

closemsg db 10,13,"File Closed Successfully"
closemsg_len equ $-closemsg

errormsg db 10,13,"Failed to open file", 0xa
errormsg_len equ $-errormsg

space db " "
space_len equ $ - space

sortmsg db 10,13,"After Sorting "
sortmsg_len equ $-sortmsg

f1name db 'input.txt'

Section .bss
buffer resb 200
bufercpy resb 200
bufferlen resb 8
cnt1 resb 8
cnt2 resb 8
fdisplay resb 8

Section .text
global _start
_start:

file 2, f1name, 2, 777      ;Opening file

mov qword[fdisplay], rax      ;RAX contains file descriptor value
bt rax, 63             ;63rd bit is +ve(0) if file is successfull opened else it is -ve (1)
                        ;Here we are checking for MSB if MSB is 1 that means -ve and if MSB is 0 that means +ve
jc ERROR

print openmsg, openmsg_len
jmp next1

ERROR:
print errormsg, errormsg_len
jmp EXIT

next1:
file 0,[fdisplay] ,buffer,200     ;reading contents of file in buffer
                     ;rax contains actual number of bytes read
 mov qword[bufferlen],rax         ;for rounds
 mov qword[cnt1],rax
 mov qword[cnt2],rax


BUBBLE:
mov al,byte[cnt2]
 mov byte[cnt1],al
 dec byte[cnt1]

mov rsi,buffer
mov rdi,buffer+1

loop:
mov bl,byte[rsi]
mov cl,byte[rdi]
 cmp bl,cl
 ja SWAP
 inc rsi
 inc rdi
 dec byte[cnt1]
 jnz loop
dec byte[bufferlen]
jnz BUBBLE
jmp END
SWAP:
 ;mov al,byte[rsi]
 mov byte[rsi],cl
 mov byte[rdi],bl
 inc rsi
 inc rdi
 dec byte[cnt1]
 jnz loop
dec byte[bufferlen]
jnz BUBBLE

END:
print sortmsg,sortmsg_len
print buffer,qword[cnt2]

file 1,qword[fdisplay],sortmsg,sortmsg_len      ;writing to input.txt
file 1,qword[fdisplay],buffer,qword[cnt2]          ;writing to input.txt

;Closing file2

mov rax,3
mov rdi,f1name
syscall
print closemsg,closemsg_len

EXIT:
 mov rax,60
 mov rdi,0
 syscall


input.txt (Store following numbers in the file)

6 3 1 5 2 9 8 7

OUTPUT:
swlab@swlab-H81-M1:~$ nasm -f elf64 bsort.asm
swlab@swlab-H81-M1:~$ ld -o bsort bsort.o
swlab@swlab-H81-M1:~$ ./bsort

File Opened Successfully
After Sorting
       12356789
File Closed Successfully


swlab@swlab-H81-M1:~$

Thursday, March 15, 2018

6. Write X86/64 ALP to switch from real mode to protected mode and display the values of GDTR, LDTR, IDTR, TR and MSW Registers.

;This program first check the mode of processor(Real or Protected),
;then reads GDTR, LDTR, IDTR, TR & MSW and displays the same.

%macro disp 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data
rmodemsg db 10,13,"Processor is in Real Mode"
rmsg_len equ $-rmodemsg

pmodemsg db 10,13,"Processor is in Protected Mode"
pmsg_len:equ $-pmodemsg

gdtmsg db 10,13,"GDT Contents are::"
gmsg_len:equ $-gdtmsg

ldtmsg db 10,13,"LDT Contents are::"
lmsg_len equ $-ldtmsg

idtmsg db 10,13,"IDT Contents are::"
imsg_len equ $-idtmsg

trmsg db 10,13,"Task Register Contents are::"
tmsg_len equ $-trmsg

mswmsg db 10,13,"Machine Status Word::"
   
mmsg_len:equ $-mswmsg
colmsg db ':'
   
nwline db 10


section .bss
gdt resd 1
    resw 1
   
ldt resw 1

idt resd 1
    resw 1

tr  resw 1
cr0_data resd 1
dnum_buff resb 04

section .text
global _start

_start:
smsw eax        ;Reading CR0
mov [cr0_data],eax
bt eax,0        ;Checking PE bit(LSB), if 1=Protected Mode, else Real Mode
jc prmode
disp rmodemsg,rmsg_len
jmp nxt1

prmode:   
disp pmodemsg,pmsg_len

nxt1:   
sgdt [gdt]
sldt [ldt]
sidt [idt]
str [tr]

disp gdtmsg,gmsg_len
mov bx,[gdt+4]
call disp_num

mov bx,[gdt+2]
call disp_num

disp colmsg,1
mov bx,[gdt]
call disp_num
   
disp ldtmsg,lmsg_len
mov bx,[ldt]
call disp_num

disp idtmsg,imsg_len
mov bx,[idt+4]
call disp_num

mov bx,[idt+2]
call disp_num

   
disp colmsg,1
mov bx,[idt]
call disp_num

disp trmsg,tmsg_len
mov bx,[tr]
call disp_num

disp mswmsg,mmsg_len
mov bx,[cr0_data+2]
call disp_num

mov bx,[cr0_data]
call disp_num

disp nwline,1

exit:   
mov eax,01
mov ebx,00
int 80h

disp_num:
mov esi,dnum_buff     ;point esi to buffer
mov ecx,04        ;load number of digits to display

up1:
rol bx,4        ;rotate number left by four bits
mov dl,bl        ;move lower byte in dl
and dl,0fh        ;mask upper digit of byte in dl
add dl,30h        ;add 30h to calculate ASCII code
cmp dl,39h        ;compare with 39h
jbe skip1        ;if less than 39h skip adding 07 more
add dl,07h        ;else add 07

skip1:
mov [esi],dl        ;store ASCII code in buffer
inc esi            ;point to next byte
dec ecx
jnz up1            ;decrement the count of digits to display
            ;if not zero jump to repeat
disp dnum_buff,4    ;display the number from buffer
ret


OUTPUT:
swlab@swlab-H81-M1:~$ nasm -f elf msw.asm
swlab@swlab-H81-M1:~$ ld -m elf_i386 -s -o msw msw.o
swlab@swlab-H81-M1:~$ ./msw

Processor is in Protected Mode
GDT Contents are::1FA89000:007F
LDT Contents are::0000
IDT Contents are::FF578000:0FFF
Task Register Contents are::0040
Machine Status Word::80050033
swlab@swlab-H81-M1:~$

Write an Assembly Language Program (ALP) to find the largest of given byte / Word / Double-word / 64-bit numbers.

  %macro scall 4 ;macro declaration with 4 parameters          mov eax , %1 ;1st p...