Sunday, 5 February 2017

8 bit microprocessor code refresher (assembly programming)

It has been long since I looked at the lowest level programming, probably first since 2000.
Problem / assignment
int i =  14
int j = 28
printf (“%d”, i + j)
result -> 42

4 bit mnemonic table used on 8 bit processor:
0
0
0
0
NOP
No operation
0
0
0
1
LDA
Load data from given memory address into register A
0
0
1
0
ADD
Add register A with given address and store the result in register A
0
0
1
1
SUB
Subtract A with given address and store the result in register A
0
1
0
0
STA
Store register A data into given memory
0
1
0
1
OUT
Copy register A to output (display)
0
1
1
0
JMP
Jump to PC to given address
0
1
1
1
LDI
Load value into the register A
1
0
0
0
JC
Jump is carry is set
1
1
1
1
HLT
Halt the execution

Binary code version:

Address
Instruction (mnemonic)
Data

0
LDA
4
Copy address 4 data into A
1
ADD
5
Add address 5 data with A and store in A
2
OUT

Display the A data [ replacement of ‘printf’ ]
3
HLT

Halt the execution
4
NOP
14
14 value at address 4  [replacement of ‘int i = 14’]
5
NOP
28
28 value at address 5 [replacement of  ‘int j = 28’]


Thanks for Ben Eater  for sharing this video:


Screenshot of same from video.


Tuesday, 31 January 2017

Gradle MavenPublication : generating POM having dependencies


Maven publishing: The publication doesn't know about dependencies, so generating dependencies will have to done manually. In our case we wanted to generate dependencies in below format:





Following Groovy code used to generate the dependencies :

        project.publishing {
                publications {
                      // specify the artifacts to publish
                      artifact source: ............................
                      .....................................................
                      .....................................................
                      pom.withXml {
                            def dependenciesNode = asNode().appendNode('dependencies')

            // We only wanted to publish 'compile' dependencies, can publish 
            // all dependencies if needed to be
                            project.configurations.compile.allDependencies.each { ModuleDependency dp ->
                            dp.artifacts.each { artifact ->
                                  def dependencyNode = dependenciesNode.appendNode('dependency')
                                  dependencyNode.appendNode('groupId', dp.group)
                                  dependencyNode.appendNode('artifactId', dp.name)
                                  dependencyNode.appendNode('version', dp.version)
                                  dependencyNode.appendNode('type',  artifact.type)
                                  dependencyNode.appendNode('classifier',  artifact.classifier)
                                  // for exclusions
                                  def exclusions = dependencyNode.appendNode('exclusions')
                                  dp.excludeRules.each { ExcludeRule ex ->
                                          def exclusion = exclusions.appendNode('exclusion')
                                          exclusion.appendNode('groupId', ex.group)
                                          exclusion.appendNode('artifactId', ex.module)
                                    }
                              }
                         }
                    }
               }

Tuesday, 17 January 2017

Thursday, 12 January 2017

Creating maven repository from Gradle dependencies (upload on local artifactory)

1)      Take back-up of $USER_HOME/.m2/repository  folder and perform 'gradle install'
>> gradle install

2)      ‘gradle install’ will build file ‘build/poms/pom-default.xml’ 
        Note: Skip the gradle install step, if you already have 'pom' file.

3)      To download the all the dependencies with the following  Maven command using ‘pom-default.xml’.  (Internet proxy settings must be correctly set in $USER_HOME/.m2/settings.xml )
>> mvn dependency:copy-dependencies -Dmdep.copyPom=true -Dmdep.useRepositoryLayout=true -Dmdep.addParentPoms=true
Note: Need maven-dependency-plugin:2.9 or above for “addParentPoms” to work.

4)      The entire dependency files will be downloaded in $USER_HOME/.m2/repository, which can be directly uploaded into the artifactory.


    

Monday, 9 January 2017

Parameter substitution in Linux shell



 
Following the  table of parameter substitution in shell based on if parameter is set / empty (‘null’) / or unset:

+--------------------+----------------------+-----------------+-----------------+
|                    |         Set          |   Empty('null') |      Unset      |
+--------------------+----------------------+-----------------+-----------------+
| ${parameter:-word} | substitute parameter | substitute word | substitute word |
| ${parameter-word}  | substitute parameter | substitute null | substitute word |
| ${parameter:=word} | substitute parameter | assign word     | assign word     |
| ${parameter=word}  | substitute parameter | substitute null | assign word     |
| ${parameter:?word} | substitute parameter | error, exit     | error, exit     |
| ${parameter?word}  | substitute parameter | substitute null | error, exit     |
| ${parameter:+word} | substitute word      | substitute null | substitute null |
| ${parameter+word}  | substitute word      | substitute word | substitute null |
+--------------------+----------------------+-----------------+-----------------+


${parameter-substitute_value} --> Use substitute only if parameter is 'not set' 
${parameter:-substitute_value} --> Use substitute when parameter is 'not set' and also when parameter is set but empty ('null')


Thursday, 8 December 2016

Adding environment from external/workspace file into the Jenkins pipeline



// Reading workspace inside pipeline script file using 'readProperties or readFile', 

def props = readProperties file: 'tempFiles/env.properties'

// Adding environment into the Jenkins:
props.each { name, val ->
   println "Exporting to Jenkins environment: " + name + "="  + val
   env."$name" = "$val"
}

Total Pageviews

Popular Posts